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