Update deployer/gradio_generator.py
Browse files- deployer/gradio_generator.py +26 -9
deployer/gradio_generator.py
CHANGED
|
@@ -1,17 +1,34 @@
|
|
|
|
|
| 1 |
import gradio as gr
|
| 2 |
-
from deployer.
|
| 3 |
|
| 4 |
-
|
| 5 |
-
|
| 6 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 7 |
|
| 8 |
-
|
| 9 |
-
|
| 10 |
-
|
|
|
|
| 11 |
|
| 12 |
-
|
|
|
|
|
|
|
| 13 |
|
| 14 |
-
#
|
| 15 |
btn.click(fn=robot_behavior, inputs=[inp], outputs=[out])
|
| 16 |
|
| 17 |
return demo
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# gradio_generator.py - FINAL CPU & Spaces-Compatible Version
|
| 2 |
import gradio as gr
|
| 3 |
+
from deployer.simulator_interface import VirtualRobot
|
| 4 |
|
| 5 |
+
# Robot behavior logic
|
| 6 |
+
def robot_behavior(user_input: str):
|
| 7 |
+
bot = VirtualRobot()
|
| 8 |
+
user_input = user_input.lower().strip()
|
| 9 |
+
|
| 10 |
+
if any(greet in user_input for greet in ["hello", "hi", "hey", "welcome"]):
|
| 11 |
+
return bot.perform_action("wave") + "\n" + bot.perform_action("say Hello there!")
|
| 12 |
+
elif user_input.startswith("say"):
|
| 13 |
+
return bot.perform_action(user_input)
|
| 14 |
+
else:
|
| 15 |
+
return bot.perform_action("say I didn't understand that. Try again!")
|
| 16 |
|
| 17 |
+
# Build Gradio app properly inside Blocks context
|
| 18 |
+
def launch_gradio_app(title="RoboSage App", description="Your robot, your voice."):
|
| 19 |
+
with gr.Blocks() as demo:
|
| 20 |
+
gr.Markdown(f"# 🤖 {title}\n{description}")
|
| 21 |
|
| 22 |
+
inp = gr.Textbox(label="Speak or Type", lines=1)
|
| 23 |
+
out = gr.Textbox(label="Robot Response")
|
| 24 |
+
btn = gr.Button("Send")
|
| 25 |
|
| 26 |
+
# Attach click event after elements are created
|
| 27 |
btn.click(fn=robot_behavior, inputs=[inp], outputs=[out])
|
| 28 |
|
| 29 |
return demo
|
| 30 |
+
|
| 31 |
+
# For local testing
|
| 32 |
+
if __name__ == "__main__":
|
| 33 |
+
app = launch_gradio_app()
|
| 34 |
+
app.launch()
|