Update deployer/simulator_interface.py
Browse files- deployer/simulator_interface.py +41 -25
deployer/simulator_interface.py
CHANGED
@@ -1,38 +1,54 @@
|
|
|
|
1 |
import time
|
2 |
import logging
|
3 |
|
|
|
|
|
4 |
class VirtualRobot:
|
5 |
-
"""
|
6 |
-
|
|
|
|
|
|
|
7 |
def __init__(self):
|
8 |
self.state = "IDLE"
|
9 |
-
logging.info("π€
|
10 |
-
|
11 |
-
def perform_action(self, command):
|
12 |
-
"""Main command processor with validation"""
|
13 |
-
command = (command or "").strip().lower()
|
14 |
-
|
15 |
-
if not command:
|
16 |
-
return "β Please enter a command"
|
17 |
-
|
18 |
-
if command == "wave":
|
19 |
-
return self._wave()
|
20 |
-
elif command.startswith("say"):
|
21 |
-
return self._speak(command[3:].strip())
|
22 |
-
return "β Try 'wave' or 'say [message]'"
|
23 |
|
24 |
-
def
|
25 |
-
"""
|
|
|
|
|
|
|
26 |
self.state = "WAVING"
|
27 |
time.sleep(0.5)
|
28 |
self.state = "IDLE"
|
29 |
-
return "
|
30 |
|
31 |
-
def
|
32 |
-
"""
|
33 |
-
|
34 |
-
|
|
|
35 |
self.state = "SPEAKING"
|
36 |
-
time.sleep(
|
37 |
self.state = "IDLE"
|
38 |
-
return f"π£οΈ {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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 |
+
Simulated robot that can wave, speak, and perform simple commands.
|
10 |
+
Useful for prototyping in CPU-only environments like Hugging Face Spaces.
|
11 |
+
"""
|
12 |
+
|
13 |
def __init__(self):
|
14 |
self.state = "IDLE"
|
15 |
+
logging.info("[π€] VirtualRobot initialized: state=IDLE")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
16 |
|
17 |
+
def wave(self) -> str:
|
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 "π€ *waves*"
|
26 |
|
27 |
+
def speak(self, text: str) -> str:
|
28 |
+
"""
|
29 |
+
Simulate robot speech.
|
30 |
+
"""
|
31 |
+
logging.info(f"[π¬] VirtualRobot: speaking -> '{text}'")
|
32 |
self.state = "SPEAKING"
|
33 |
+
time.sleep(0.5)
|
34 |
self.state = "IDLE"
|
35 |
+
return f"π£οΈ {text}"
|
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}"
|