mgbam commited on
Commit
c5f750a
Β·
verified Β·
1 Parent(s): 5223de6

Update deployer/simulator_interface.py

Browse files
Files changed (1) hide show
  1. deployer/simulator_interface.py +41 -19
deployer/simulator_interface.py CHANGED
@@ -1,32 +1,54 @@
 
1
  import time
2
  import logging
3
- from typing import Optional
 
4
 
5
  class VirtualRobot:
 
 
 
 
 
6
  def __init__(self):
7
  self.state = "IDLE"
8
- logging.basicConfig(level=logging.INFO)
9
- logging.info("Robot initialized")
10
-
11
- def perform_action(self, action: str) -> str:
12
- action = action.lower().strip()
13
-
14
- if action == "wave":
15
- return self._wave()
16
- elif action.startswith("say"):
17
- return self._speak(action[3:].strip())
18
- return "❓ Unknown command"
19
 
20
- def _wave(self) -> str:
 
 
 
 
21
  self.state = "WAVING"
22
  time.sleep(0.5)
23
  self.state = "IDLE"
24
- return "πŸ‘‹ Wave complete!"
25
 
26
- def _speak(self, message: str) -> str:
27
- if not message:
28
- return "❌ No message provided"
 
 
29
  self.state = "SPEAKING"
30
- time.sleep(max(0.3, len(message)*0.05))
31
  self.state = "IDLE"
32
- return f"πŸ—£οΈ {message.capitalize()}"
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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}"