robosage / deployer /simulator_interface.py
mgbam's picture
Update deployer/simulator_interface.py
ae848b5 verified
raw
history blame
1.67 kB
# simulator_interface.py - Robot app simulator for Hugging Face Spaces (CPU only)
import time
import logging
logging.basicConfig(level=logging.INFO)
class VirtualRobot:
"""
Simulated robot that can wave, speak, and perform simple commands.
Useful for prototyping in CPU-only environments like Hugging Face Spaces.
"""
def __init__(self):
self.state = "IDLE"
logging.info("[πŸ€–] VirtualRobot initialized: state=IDLE")
def wave(self) -> str:
"""
Simulate an arm wave action.
"""
logging.info("[πŸ–οΈ] VirtualRobot: waving")
self.state = "WAVING"
time.sleep(0.5)
self.state = "IDLE"
return "πŸ€– *waves*"
def speak(self, text: str) -> str:
"""
Simulate robot speech.
"""
logging.info(f"[πŸ’¬] VirtualRobot: speaking -> '{text}'")
self.state = "SPEAKING"
time.sleep(0.5)
self.state = "IDLE"
return f"πŸ—£οΈ {text}"
def perform_action(self, command: str) -> str:
"""
Parse and execute a command. Supports:
- "wave": calls wave()
- "say <message>": calls speak(message)
Returns an error message for unknown commands.
"""
parts = command.strip().split(" ", 1)
action = parts[0].lower()
arg = parts[1] if len(parts) > 1 else ""
if action == "wave":
return self.wave()
elif action == "say" and arg:
return self.speak(arg)
else:
logging.warning(f"[⚠️] VirtualRobot: unknown command '{command}'")
return f"❓ Unknown action: {command}"