mgbam commited on
Commit
630a481
·
verified ·
1 Parent(s): 054b40b

Update deployer/gradio_generator.py

Browse files
Files changed (1) hide show
  1. deployer/gradio_generator.py +26 -9
deployer/gradio_generator.py CHANGED
@@ -1,17 +1,34 @@
 
1
  import gradio as gr
2
- from deployer.real_robot_bridge import robot_behavior
3
 
4
- def launch_gradio_app():
5
- with gr.Blocks() as demo:
6
- gr.Markdown("## 🤖 Robot App Control Panel")
 
 
 
 
 
 
 
 
7
 
8
- with gr.Row():
9
- inp = gr.Textbox(label="Give your robot a task...")
10
- out = gr.Textbox(label="Robot response", interactive=False)
 
11
 
12
- btn = gr.Button("🟢 Run Robot")
 
 
13
 
14
- # IMPORTANT: attach callback inside the same gr.Blocks() context
15
  btn.click(fn=robot_behavior, inputs=[inp], outputs=[out])
16
 
17
  return demo
 
 
 
 
 
 
1
+ # gradio_generator.py - FINAL CPU & Spaces-Compatible Version
2
  import gradio as gr
3
+ from deployer.simulator_interface import VirtualRobot
4
 
5
+ # Robot behavior logic
6
+ def robot_behavior(user_input: str):
7
+ bot = VirtualRobot()
8
+ user_input = user_input.lower().strip()
9
+
10
+ if any(greet in user_input for greet in ["hello", "hi", "hey", "welcome"]):
11
+ return bot.perform_action("wave") + "\n" + bot.perform_action("say Hello there!")
12
+ elif user_input.startswith("say"):
13
+ return bot.perform_action(user_input)
14
+ else:
15
+ return bot.perform_action("say I didn't understand that. Try again!")
16
 
17
+ # Build Gradio app properly inside Blocks context
18
+ def launch_gradio_app(title="RoboSage App", description="Your robot, your voice."):
19
+ with gr.Blocks() as demo:
20
+ gr.Markdown(f"# 🤖 {title}\n{description}")
21
 
22
+ inp = gr.Textbox(label="Speak or Type", lines=1)
23
+ out = gr.Textbox(label="Robot Response")
24
+ btn = gr.Button("Send")
25
 
26
+ # Attach click event after elements are created
27
  btn.click(fn=robot_behavior, inputs=[inp], outputs=[out])
28
 
29
  return demo
30
+
31
+ # For local testing
32
+ if __name__ == "__main__":
33
+ app = launch_gradio_app()
34
+ app.launch()