mgbam commited on
Commit
2e93b96
·
verified ·
1 Parent(s): 839548e

Update deployer/gradio_generator.py

Browse files
Files changed (1) hide show
  1. deployer/gradio_generator.py +46 -40
deployer/gradio_generator.py CHANGED
@@ -1,52 +1,58 @@
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 create_interface():
16
- """Create the Gradio interface components"""
17
- with gr.Blocks() as demo:
18
- gr.Markdown("# 🤖 RoboSage App\n\nYour robot, your voice.")
19
 
20
- with gr.Row():
21
- input_text = gr.Textbox(label="Speak or Type", lines=1)
22
- send_button = gr.Button("Send", variant="primary")
23
-
24
- output_text = gr.Textbox(label="Robot Response", interactive=False)
25
-
26
- # Event handlers
27
- send_button.click(
28
- fn=robot_behavior,
29
- inputs=input_text,
30
- outputs=output_text
31
- )
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
32
 
33
- input_text.submit(
34
- fn=robot_behavior,
35
- inputs=input_text,
36
- outputs=output_text
37
- )
38
-
39
- return demo
40
 
41
- def launch_gradio_app(title="RoboSage App", description="Your robot, your voice."):
42
- """Launch the Gradio application"""
43
- interface = create_interface()
44
- return interface
45
 
46
  if __name__ == "__main__":
47
- app = launch_gradio_app()
48
- app.launch(
 
49
  server_name="0.0.0.0",
50
  server_port=7860,
51
- share=False
 
52
  )
 
1
  import gradio as gr
2
  from deployer.simulator_interface import VirtualRobot
3
 
4
+ class RoboSageApp:
5
+ def __init__(self):
6
+ self.bot = VirtualRobot()
7
+ self.interface = self._create_interface()
 
 
 
 
 
 
8
 
9
+ def _robot_behavior(self, user_input: str):
10
+ """Handle robot interaction logic"""
11
+ text = user_input.lower().strip()
 
12
 
13
+ if any(g in text for g in ["hello", "hi", "hey", "welcome"]):
14
+ return self.bot.perform_action("wave") + "\n" + self.bot.perform_action("say Hello there!")
15
+ if text.startswith("say"):
16
+ return self.bot.perform_action(text)
17
+ return self.bot.perform_action("say I didn't understand that. Try again!")
18
+
19
+ def _create_interface(self):
20
+ """Create the Gradio interface with proper component binding"""
21
+ with gr.Blocks() as demo:
22
+ gr.Markdown("# 🤖 RoboSage App\n\nYour robot, your voice.")
23
+
24
+ with gr.Row():
25
+ self.input_text = gr.Textbox(label="Speak or Type", lines=1)
26
+ self.send_button = gr.Button("Send", variant="primary")
27
+
28
+ self.output_text = gr.Textbox(label="Robot Response", interactive=False)
29
+
30
+ # Event handlers using bound methods
31
+ self.send_button.click(
32
+ fn=self._robot_behavior,
33
+ inputs=self.input_text,
34
+ outputs=self.output_text
35
+ )
36
+
37
+ self.input_text.submit(
38
+ fn=self._robot_behavior,
39
+ inputs=self.input_text,
40
+ outputs=self.output_text
41
+ )
42
 
43
+ return demo
 
 
 
 
 
 
44
 
45
+ def launch_gradio_app():
46
+ """Launch the application with proper component lifecycle management"""
47
+ app = RoboSageApp()
48
+ return app.interface
49
 
50
  if __name__ == "__main__":
51
+ # For local testing with explicit configuration
52
+ interface = launch_gradio_app()
53
+ interface.launch(
54
  server_name="0.0.0.0",
55
  server_port=7860,
56
+ share=False,
57
+ ssr_mode=False # Explicitly disable SSR if not needed
58
  )