Update deployer/gradio_generator.py
Browse files- deployer/gradio_generator.py +11 -13
deployer/gradio_generator.py
CHANGED
@@ -1,9 +1,9 @@
|
|
1 |
-
# gradio_generator.py -
|
2 |
|
3 |
import gradio as gr
|
4 |
from deployer.simulator_interface import VirtualRobot
|
5 |
|
6 |
-
#
|
7 |
def robot_behavior(user_input: str):
|
8 |
bot = VirtualRobot()
|
9 |
user_input = user_input.lower().strip()
|
@@ -15,22 +15,20 @@ def robot_behavior(user_input: str):
|
|
15 |
else:
|
16 |
return bot.perform_action("say I didn't understand that. Try again!")
|
17 |
|
18 |
-
# Generate Gradio app
|
19 |
def launch_gradio_app(title="RoboSage App", description="Your robot, your voice."):
|
20 |
-
|
21 |
-
gr.
|
22 |
-
{description}
|
23 |
-
""")
|
24 |
-
with gr.Row():
|
25 |
inp = gr.Textbox(label="Speak or Type")
|
26 |
out = gr.Textbox(label="Robot Response")
|
27 |
-
|
|
|
|
|
28 |
|
29 |
-
|
30 |
|
31 |
-
|
32 |
-
|
33 |
-
# For testing
|
34 |
if __name__ == "__main__":
|
35 |
app = launch_gradio_app()
|
36 |
app.launch()
|
|
|
1 |
+
# gradio_generator.py - Safe version for Hugging Face Spaces
|
2 |
|
3 |
import gradio as gr
|
4 |
from deployer.simulator_interface import VirtualRobot
|
5 |
|
6 |
+
# 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()
|
|
|
15 |
else:
|
16 |
return bot.perform_action("say I didn't understand that. Try again!")
|
17 |
|
18 |
+
# Generate Gradio app
|
19 |
def launch_gradio_app(title="RoboSage App", description="Your robot, your voice."):
|
20 |
+
def create_ui():
|
21 |
+
with gr.Blocks() as demo:
|
22 |
+
gr.Markdown(f"# 🤖 {title}\n{description}")
|
|
|
|
|
23 |
inp = gr.Textbox(label="Speak or Type")
|
24 |
out = gr.Textbox(label="Robot Response")
|
25 |
+
btn = gr.Button("Send")
|
26 |
+
btn.click(fn=robot_behavior, inputs=inp, outputs=out)
|
27 |
+
return demo
|
28 |
|
29 |
+
return create_ui()
|
30 |
|
31 |
+
# Run directly
|
|
|
|
|
32 |
if __name__ == "__main__":
|
33 |
app = launch_gradio_app()
|
34 |
app.launch()
|