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