Update deployer/gradio_generator.py
Browse files- deployer/gradio_generator.py +9 -16
deployer/gradio_generator.py
CHANGED
@@ -1,10 +1,7 @@
|
|
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,25 +13,21 @@ def robot_behavior(user_input: str):
|
|
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 |
-
|
|
|
|
|
23 |
inp = gr.Textbox(label="Speak or Type", lines=1)
|
24 |
out = gr.Textbox(label="Robot Response")
|
|
|
25 |
|
26 |
-
|
27 |
-
|
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
|
36 |
|
37 |
-
#
|
38 |
if __name__ == "__main__":
|
39 |
app = launch_gradio_app()
|
40 |
app.launch()
|
|
|
|
|
|
|
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 |
user_input = user_input.lower().strip()
|
|
|
13 |
else:
|
14 |
return bot.perform_action("say I didn't understand that. Try again!")
|
15 |
|
16 |
+
# Build Gradio app (correct order)
|
|
|
17 |
def launch_gradio_app(title="RoboSage App", description="Your robot, your voice."):
|
18 |
+
with gr.Blocks() as demo:
|
19 |
+
gr.Markdown(f"# 🤖 {title}\n{description}")
|
20 |
+
|
21 |
inp = gr.Textbox(label="Speak or Type", lines=1)
|
22 |
out = gr.Textbox(label="Robot Response")
|
23 |
+
btn = gr.Button("Send")
|
24 |
|
25 |
+
# 🔧 Must be called after all are inside the Blocks layout
|
26 |
+
btn.click(fn=robot_behavior, inputs=inp, outputs=out)
|
|
|
|
|
|
|
|
|
|
|
|
|
27 |
|
28 |
+
return demo
|
29 |
|
30 |
+
# For local testing
|
31 |
if __name__ == "__main__":
|
32 |
app = launch_gradio_app()
|
33 |
app.launch()
|