# 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}" | |