-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathjarvis_desktop_automation.py
More file actions
310 lines (268 loc) Β· 10.8 KB
/
jarvis_desktop_automation.py
File metadata and controls
310 lines (268 loc) Β· 10.8 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
#!/usr/bin/env python3
"""
JARVIS Mark 5 - Desktop Automation & Media Control Interface
Natural language interface for desktop automation, camera control, and media management
"""
import asyncio
import logging
import sys
import os
import re
from typing import Dict, Any, Optional, List
# Add paths
sys.path.append(os.path.join(os.path.dirname(__file__), 'backend'))
sys.path.append(os.path.join(os.path.dirname(__file__), 'RAVANA'))
# pylint: disable=wrong-import-position
from backend.modules.desktop_automation import DesktopAutomation
logger = logging.getLogger(__name__)
class JARVISDesktopInterface:
"""Natural language interface for JARVIS desktop automation and media control"""
def __init__(self):
self.logger = logging.getLogger(__name__)
self.desktop_automation = DesktopAutomation()
self.command_patterns = self._initialize_command_patterns()
self.logger.info("JARVIS Desktop Interface initialized")
# Convenience methods for voice commands
def open_application(self, app_name: str) -> Dict[str, Any]:
"""Open an application"""
return self.desktop_automation.open_application(app_name)
def take_screenshot(self, save_path: str = None) -> Dict[str, Any]:
"""Take a screenshot"""
return self.desktop_automation.take_screenshot(save_path)
def take_picture(self, save_path: str = None) -> Dict[str, Any]:
"""Take a picture with camera"""
return self.desktop_automation.snap_picture(save_path)
def start_screen_recording(self, duration_seconds: int = 10,
save_path: str = None) -> Dict[str, Any]:
"""Start screen recording"""
return self.desktop_automation.start_screen_recording(duration_seconds, save_path)
def type_text(self, text: str) -> Dict[str, Any]:
"""Type text"""
return self.desktop_automation.type_text(text)
def _initialize_command_patterns(self) -> Dict[str, Dict[str, Any]]:
"""Initialize natural language command patterns for desktop automation"""
return {
# Camera Control Patterns
"camera_control": {
"patterns": [
r"take\s+(?:a\s+)?picture",
r"snap\s+(?:a\s+)?(?:photo|pic)",
r"capture\s+(?:a\s+)?(?:photo|image)",
r"open\s+camera",
r"start\s+camera",
r"launch\s+camera",
r"record\s+(?:a\s+)?video",
r"take\s+(?:a\s+)?video",
r"start\s+recording",
r"stop\s+recording",
r"(?:jarvis|j|buddy)[,\s]*(?:take\s+(?:a\s+)?picture|"
r"snap\s+(?:a\s+)?(?:photo|pic)|"
r"capture\s+(?:a\s+)?(?:photo|image)|"
r"open\s+camera|start\s+camera|launch\s+camera|"
r"record\s+(?:a\s+)?video|take\s+(?:a\s+)?video|"
r"start\s+recording|stop\s+recording)"
],
"category": "camera"
},
# Screenshot & Screen Recording Patterns
"screen_control": {
"patterns": [
r"take\s+screenshot",
r"capture\s+screen",
r"record\s+(?:my\s+)?screen",
r"screen\s+recording",
r"record\s+desktop",
r"(?:jarvis|j|buddy)[,\s]*(?:take\s+screenshot|"
r"capture\s+screen|record\s+(?:my\s+)?screen|"
r"screen\s+recording|record\s+desktop)"
],
"category": "screen"
},
# Application Control Patterns
"app_control": {
"patterns": [
r"open\s+(\w+)",
r"launch\s+(\w+)",
r"start\s+(\w+)",
r"close\s+(\w+)",
r"quit\s+(\w+)",
r"exit\s+(\w+)"
],
"category": "application"
},
# YouTube & Media Patterns
"media_control": {
"patterns": [
r"search\s+youtube\s+for\s+(.+)",
r"youtube\s+(.+)",
r"find\s+video\s+(.+)",
r"play\s+video\s+(.+)",
r"watch\s+(.+)",
r"download\s+video\s+(.+)",
r"save\s+video\s+(.+)"
],
"category": "media"
},
# Google Search Patterns
"web_search": {
"patterns": [
r"search\s+google\s+for\s+(.+)",
r"google\s+(.+)",
r"search\s+for\s+(.+)",
r"look\s+up\s+(.+)"
],
"category": "search"
},
# Desktop Automation Patterns
"desktop_automation": {
"patterns": [
r"click\s+at\s+(\d+)\s+(\d+)",
r"click\s+(\d+)\s+(\d+)",
r"type\s+(.+)",
r"write\s+(.+)",
r"enter\s+(.+)",
r"press\s+(\w+)",
r"hit\s+(\w+)",
r"key\s+(\w+)"
],
"category": "automation"
},
# Help Patterns
"help": {
"patterns": [
r"help",
r"what\s+can\s+you\s+do",
r"commands",
r"show\s+help",
r"desktop\s+help"
],
"category": "help"
}
}
def parse_command(self, command: str) -> Optional[Dict[str, Any]]:
"""Parse natural language command and return action details"""
command = command.lower().strip()
for action_name, action_info in self.command_patterns.items():
for pattern in action_info["patterns"]:
match = re.search(pattern, command, re.IGNORECASE)
if match:
return {
"action": action_name,
"category": action_info["category"],
"matches": match.groups(),
"original_command": command,
"pattern": pattern
}
return None
async def execute_command(self, command: str) -> Dict[str, Any]:
"""Execute a natural language desktop automation command"""
try:
# Parse the command
parsed = self.parse_command(command)
if not parsed:
return {
"success": False,
"error": f"I don't understand the command: '{command}'",
"message": "Try saying something like 'take picture' or 'open notepad'",
"suggestions": [
"take picture",
"open camera",
"record video for 30 seconds",
"take screenshot",
"open notepad",
"search youtube for funny cats",
"search google for python tutorial",
"help"
]
}
# Execute the command using desktop automation
result = self.desktop_automation.process_natural_command(command)
# Add parsing information to result
result["parsed_command"] = parsed
result["timestamp"] = asyncio.get_event_loop().time()
return result
except (ValueError, KeyError, TypeError, AttributeError) as e:
self.logger.error("Error executing command '%s': %s", command, e)
return {
"success": False,
"error": str(e),
"message": "An error occurred while executing the command"
}
def get_available_commands(self) -> List[str]:
"""Get list of example commands"""
return [
# Camera commands
"take picture",
"open camera",
"record video for 30 seconds",
"stop recording",
# Screen commands
"take screenshot",
"record screen for 60 seconds",
# Application commands
"open notepad",
"open chrome",
"open calculator",
"close notepad",
# Media commands
"search youtube for funny cats",
"play video https://youtube.com/watch?v=example",
"download video https://youtube.com/watch?v=example",
# Search commands
"search google for python tutorial",
"google artificial intelligence",
# Desktop automation
"click at 500 300",
"type hello world",
"press enter",
# Help
"help"
]
def get_capabilities(self) -> Dict[str, Any]:
"""Get current capabilities and status"""
status = self.desktop_automation.get_status()
return {
"interface": "JARVIS Desktop Automation",
"version": "1.0.0",
"desktop_automation": status,
"supported_commands": len(self.get_available_commands()),
"command_categories": list(set(
info["category"] for info in self.command_patterns.values()
)),
"natural_language": True
}
async def main():
"""Test the desktop automation interface"""
print("π€ JARVIS DESKTOP AUTOMATION INTERFACE")
print("=" * 60)
# Initialize interface
interface = JARVISDesktopInterface()
# Test commands
test_commands = [
"take picture",
"open notepad",
"search youtube for funny cats",
"search google for python tutorial",
"take screenshot",
"help"
]
print("\nπ§ͺ Testing Desktop Automation Commands:")
print("-" * 40)
for cmd in test_commands:
print(f"\n㪠Command: '{cmd}'")
result = await interface.execute_command(cmd)
if result["success"]:
print(f"β
{result['message']}")
if "parsed_command" in result:
parsed = result["parsed_command"]
print(f" Category: {parsed['category']}")
print(f" Pattern: {parsed['pattern']}")
else:
print(f"β Error: {result['error']}")
# Show capabilities
print(f"\nπ Capabilities: {interface.get_capabilities()}")
print(f"π Available Commands: {len(interface.get_available_commands())}")
print("\nπ JARVIS Desktop Automation Interface Ready!")
print("π‘ Try saying: 'Jarvis, take a picture' or 'J, open chrome'")
if __name__ == "__main__":
asyncio.run(main())