Update deployer/gradio_generator.py
Browse files- deployer/gradio_generator.py +30 -12
deployer/gradio_generator.py
CHANGED
|
@@ -1,32 +1,50 @@
|
|
| 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 correct 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 |
-
#
|
| 20 |
-
|
| 21 |
-
|
| 22 |
-
|
| 23 |
-
|
| 24 |
-
|
| 25 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 26 |
|
| 27 |
return demo
|
| 28 |
|
| 29 |
-
# For local testing
|
| 30 |
if __name__ == "__main__":
|
| 31 |
app = launch_gradio_app()
|
| 32 |
-
app.launch(
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
import gradio as gr
|
| 2 |
from deployer.simulator_interface import VirtualRobot
|
| 3 |
|
|
|
|
| 4 |
def robot_behavior(user_input: str):
|
| 5 |
+
"""Handle robot interaction logic"""
|
| 6 |
bot = VirtualRobot()
|
| 7 |
text = user_input.lower().strip()
|
| 8 |
+
|
| 9 |
if any(g in text for g in ["hello", "hi", "hey", "welcome"]):
|
| 10 |
return bot.perform_action("wave") + "\n" + bot.perform_action("say Hello there!")
|
| 11 |
if text.startswith("say"):
|
| 12 |
return bot.perform_action(text)
|
| 13 |
return bot.perform_action("say I didn't understand that. Try again!")
|
| 14 |
|
|
|
|
| 15 |
def launch_gradio_app(title="RoboSage App", description="Your robot, your voice."):
|
| 16 |
+
"""Create and configure the Gradio interface"""
|
| 17 |
with gr.Blocks() as demo:
|
| 18 |
gr.Markdown(f"# 🤖 {title}\n\n{description}")
|
| 19 |
+
|
| 20 |
+
# Input/Output components
|
| 21 |
+
with gr.Row():
|
| 22 |
+
inp = gr.Textbox(label="Speak or Type", lines=1)
|
| 23 |
+
btn = gr.Button("Send", variant="primary")
|
| 24 |
+
|
| 25 |
+
out = gr.Textbox(label="Robot Response", interactive=False)
|
| 26 |
+
|
| 27 |
+
# Event handling
|
| 28 |
+
btn.click(
|
| 29 |
+
fn=robot_behavior,
|
| 30 |
+
inputs=inp,
|
| 31 |
+
outputs=out,
|
| 32 |
+
api_name="process_command"
|
| 33 |
+
)
|
| 34 |
+
|
| 35 |
+
# Additional UX improvements
|
| 36 |
+
inp.submit(
|
| 37 |
+
fn=robot_behavior,
|
| 38 |
+
inputs=inp,
|
| 39 |
+
outputs=out
|
| 40 |
+
)
|
| 41 |
|
| 42 |
return demo
|
| 43 |
|
|
|
|
| 44 |
if __name__ == "__main__":
|
| 45 |
app = launch_gradio_app()
|
| 46 |
+
app.launch(
|
| 47 |
+
server_name="0.0.0.0",
|
| 48 |
+
server_port=7860,
|
| 49 |
+
share=False
|
| 50 |
+
)
|