File size: 1,665 Bytes
ae848b5 90d2159 c5f750a ae848b5 90d2159 ae848b5 90d2159 ae848b5 d207de4 ae848b5 eada831 dab61c8 eada831 ae848b5 d207de4 ae848b5 eada831 ae848b5 eada831 ae848b5 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 |
# 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}"
|