mgbam commited on
Commit
ae848b5
Β·
verified Β·
1 Parent(s): b4130f2

Update deployer/simulator_interface.py

Browse files
Files changed (1) hide show
  1. 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
- """Simplified but robust virtual robot implementation"""
6
-
 
 
 
7
  def __init__(self):
8
  self.state = "IDLE"
9
- logging.info("πŸ€– Virtual Robot initialized")
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 _wave(self):
25
- """Wave action handler"""
 
 
 
26
  self.state = "WAVING"
27
  time.sleep(0.5)
28
  self.state = "IDLE"
29
- return "πŸ‘‹ Wave complete!"
30
 
31
- def _speak(self, message):
32
- """Speak action handler"""
33
- if not message:
34
- return "❌ No message provided"
 
35
  self.state = "SPEAKING"
36
- time.sleep(max(0.3, len(message)*0.05))
37
  self.state = "IDLE"
38
- 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}"