Update deployer/gradio_generator.py
Browse files- deployer/gradio_generator.py +10 -12
deployer/gradio_generator.py
CHANGED
@@ -1,29 +1,27 @@
|
|
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 |
-
|
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 |
-
|
13 |
-
return bot.perform_action(
|
14 |
-
|
15 |
-
return bot.perform_action("say I didn't understand that. Try again!")
|
16 |
|
17 |
-
# Build Gradio app
|
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 |
-
#
|
27 |
btn.click(fn=robot_behavior, inputs=[inp], outputs=[out])
|
28 |
|
29 |
return demo
|
|
|
|
|
1 |
import gradio as gr
|
2 |
from deployer.simulator_interface import VirtualRobot
|
3 |
|
4 |
# Robot behavior logic
|
5 |
def robot_behavior(user_input: str):
|
6 |
bot = VirtualRobot()
|
7 |
+
text = user_input.lower().strip()
|
8 |
+
if any(g in text for g in ["hello", "hi", "hey", "welcome"]):
|
|
|
9 |
return bot.perform_action("wave") + "\n" + bot.perform_action("say Hello there!")
|
10 |
+
if text.startswith("say"):
|
11 |
+
return bot.perform_action(text)
|
12 |
+
return bot.perform_action("say I didn't understand that. Try again!")
|
|
|
13 |
|
14 |
+
# Build Gradio app with proper Blocks context
|
15 |
def launch_gradio_app(title="RoboSage App", description="Your robot, your voice."):
|
16 |
with gr.Blocks() as demo:
|
17 |
+
gr.Markdown(f"# 🤖 {title}\n\n{description}")
|
18 |
|
19 |
+
# Define components (no trailing commas!)
|
20 |
inp = gr.Textbox(label="Speak or Type", lines=1)
|
21 |
out = gr.Textbox(label="Robot Response")
|
22 |
+
btn = gr.Button("Send", key="send-btn")
|
23 |
|
24 |
+
# Wire event inside the same Blocks context
|
25 |
btn.click(fn=robot_behavior, inputs=[inp], outputs=[out])
|
26 |
|
27 |
return demo
|