mgbam commited on
Commit
a294fd3
·
verified ·
1 Parent(s): b551edc

Update deployer/gradio_generator.py

Browse files
Files changed (1) hide show
  1. deployer/gradio_generator.py +30 -12
deployer/gradio_generator.py CHANGED
@@ -1,32 +1,50 @@
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
  text = user_input.lower().strip()
 
8
  if any(g in text for g in ["hello", "hi", "hey", "welcome"]):
9
  return bot.perform_action("wave") + "\n" + bot.perform_action("say Hello there!")
10
  if text.startswith("say"):
11
  return bot.perform_action(text)
12
  return bot.perform_action("say I didn't understand that. Try again!")
13
 
14
- # Build Gradio app with correct Blocks context
15
  def launch_gradio_app(title="RoboSage App", description="Your robot, your voice."):
 
16
  with gr.Blocks() as demo:
17
  gr.Markdown(f"# 🤖 {title}\n\n{description}")
18
-
19
- # Define components without trailing commas
20
- inp = gr.Textbox(label="Speak or Type", lines=1)
21
- out = gr.Textbox(label="Robot Response")
22
- btn = gr.Button("Send", key="send-btn")
23
-
24
- # Wire the click event inside the same Blocks context
25
- btn.click(fn=robot_behavior, inputs=[inp], outputs=[out])
 
 
 
 
 
 
 
 
 
 
 
 
 
 
26
 
27
  return demo
28
 
29
- # For local testing
30
  if __name__ == "__main__":
31
  app = launch_gradio_app()
32
- app.launch()
 
 
 
 
 
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 launch_gradio_app(title="RoboSage App", description="Your robot, your voice."):
16
+ """Create and configure the Gradio interface"""
17
  with gr.Blocks() as demo:
18
  gr.Markdown(f"# 🤖 {title}\n\n{description}")
19
+
20
+ # Input/Output components
21
+ with gr.Row():
22
+ inp = gr.Textbox(label="Speak or Type", lines=1)
23
+ btn = gr.Button("Send", variant="primary")
24
+
25
+ out = gr.Textbox(label="Robot Response", interactive=False)
26
+
27
+ # Event handling
28
+ btn.click(
29
+ fn=robot_behavior,
30
+ inputs=inp,
31
+ outputs=out,
32
+ api_name="process_command"
33
+ )
34
+
35
+ # Additional UX improvements
36
+ inp.submit(
37
+ fn=robot_behavior,
38
+ inputs=inp,
39
+ outputs=out
40
+ )
41
 
42
  return demo
43
 
 
44
  if __name__ == "__main__":
45
  app = launch_gradio_app()
46
+ app.launch(
47
+ server_name="0.0.0.0",
48
+ server_port=7860,
49
+ share=False
50
+ )