Update deployer/simulator_interface.py
Browse files- deployer/simulator_interface.py +34 -41
deployer/simulator_interface.py
CHANGED
@@ -1,54 +1,47 @@
|
|
1 |
-
# simulator_interface.py - Robot app simulator for Hugging Face Spaces (CPU only)
|
2 |
import time
|
3 |
import logging
|
4 |
|
5 |
-
logging.basicConfig(level=logging.INFO)
|
6 |
-
|
7 |
class VirtualRobot:
|
8 |
-
"""
|
9 |
-
|
10 |
-
Useful for prototyping in CPU-only environments like Hugging Face Spaces.
|
11 |
-
"""
|
12 |
-
|
13 |
def __init__(self):
|
14 |
self.state = "IDLE"
|
15 |
-
logging.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
16 |
|
17 |
-
def
|
18 |
-
"""
|
19 |
-
Simulate an arm wave action.
|
20 |
-
"""
|
21 |
-
logging.info("[ποΈ] VirtualRobot: waving")
|
22 |
self.state = "WAVING"
|
23 |
time.sleep(0.5)
|
24 |
self.state = "IDLE"
|
25 |
-
return "
|
26 |
|
27 |
-
def
|
28 |
-
"""
|
29 |
-
|
30 |
-
|
31 |
-
logging.info(f"[π¬] VirtualRobot: speaking -> '{text}'")
|
32 |
self.state = "SPEAKING"
|
33 |
-
time.sleep(0.
|
34 |
self.state = "IDLE"
|
35 |
-
return f"π£οΈ {
|
36 |
-
|
37 |
-
def perform_action(self, command: str) -> str:
|
38 |
-
"""
|
39 |
-
Parse and execute a command. Supports:
|
40 |
-
- "wave": calls wave()
|
41 |
-
- "say <message>": calls speak(message)
|
42 |
-
Returns an error message for unknown commands.
|
43 |
-
"""
|
44 |
-
parts = command.strip().split(" ", 1)
|
45 |
-
action = parts[0].lower()
|
46 |
-
arg = parts[1] if len(parts) > 1 else ""
|
47 |
-
|
48 |
-
if action == "wave":
|
49 |
-
return self.wave()
|
50 |
-
elif action == "say" and arg:
|
51 |
-
return self.speak(arg)
|
52 |
-
else:
|
53 |
-
logging.warning(f"[β οΈ] VirtualRobot: unknown command '{command}'")
|
54 |
-
return f"β Unknown action: {command}"
|
|
|
|
|
1 |
import time
|
2 |
import logging
|
3 |
|
|
|
|
|
4 |
class VirtualRobot:
|
5 |
+
"""Simplified but robust virtual robot implementation"""
|
6 |
+
|
|
|
|
|
|
|
7 |
def __init__(self):
|
8 |
self.state = "IDLE"
|
9 |
+
logging.basicConfig(
|
10 |
+
level=logging.INFO,
|
11 |
+
format='%(asctime)s - %(name)s - %(levelname)s - %(message)s'
|
12 |
+
)
|
13 |
+
self.logger = logging.getLogger("VirtualRobot")
|
14 |
+
self.logger.info("Robot initialized")
|
15 |
+
|
16 |
+
def perform_action(self, command: str) -> str:
|
17 |
+
"""Main command processor with error handling"""
|
18 |
+
try:
|
19 |
+
command = command.strip().lower()
|
20 |
+
if not command:
|
21 |
+
return "Please enter a command"
|
22 |
+
|
23 |
+
if command == "wave":
|
24 |
+
return self._handle_wave()
|
25 |
+
elif command.startswith("say"):
|
26 |
+
return self._handle_speak(command[3:].strip())
|
27 |
+
else:
|
28 |
+
return "Unknown command. Try 'wave' or 'say [message]'"
|
29 |
+
except Exception as e:
|
30 |
+
self.logger.error(f"Command failed: {str(e)}")
|
31 |
+
return f"Error: {str(e)}"
|
32 |
|
33 |
+
def _handle_wave(self) -> str:
|
34 |
+
"""Wave action handler"""
|
|
|
|
|
|
|
35 |
self.state = "WAVING"
|
36 |
time.sleep(0.5)
|
37 |
self.state = "IDLE"
|
38 |
+
return "π Wave complete!"
|
39 |
|
40 |
+
def _handle_speak(self, message: str) -> str:
|
41 |
+
"""Speak action handler"""
|
42 |
+
if not message:
|
43 |
+
return "No message provided"
|
|
|
44 |
self.state = "SPEAKING"
|
45 |
+
time.sleep(max(0.3, len(message)*0.05))
|
46 |
self.state = "IDLE"
|
47 |
+
return f"π£οΈ {message.capitalize()}"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|