mgbam commited on
Commit
8a53784
·
verified ·
1 Parent(s): 0103479

Update deployer/gradio_generator.py

Browse files
Files changed (1) hide show
  1. deployer/gradio_generator.py +22 -8
deployer/gradio_generator.py CHANGED
@@ -1,8 +1,8 @@
1
  # gradio_generator.py - CPU & Spaces-compatible Gradio interface for RoboSage
 
2
  import gradio as gr
3
  from deployer.simulator_interface import VirtualRobot
4
 
5
- # Robot behavior logic
6
  def robot_behavior(user_input: str) -> str:
7
  """Bridge between user input and VirtualRobot actions."""
8
  bot = VirtualRobot()
@@ -10,7 +10,11 @@ def robot_behavior(user_input: str) -> str:
10
 
11
  # Greeting detection
12
  if any(greet in text for greet in ["hello", "hi", "hey", "welcome"]):
13
- return bot.perform_action("wave") + "\n" + bot.perform_action("say Hello there!")
 
 
 
 
14
 
15
  # Direct speech command
16
  if text.startswith("say "):
@@ -19,21 +23,31 @@ def robot_behavior(user_input: str) -> str:
19
  # Default fallback
20
  return bot.perform_action("say I'm sorry, I didn't understand that.")
21
 
22
- # Build Gradio app with proper Blocks context
23
- def launch_gradio_app(title: str = "RoboSage App", description: str = "Your robot, your voice.") -> gr.Blocks:
 
 
 
24
  with gr.Blocks() as demo:
25
  gr.Markdown(f"# 🤖 {title}\n\n{description}")
26
 
27
- inp = gr.Textbox(label="Speak or Type", lines=1, placeholder="Type or speak your command...")
28
- out = gr.Textbox(label="Robot Response", lines=4)
 
 
 
 
 
 
 
 
29
  btn = gr.Button("Send", key="send-btn")
30
 
31
- # Wire click event inside Blocks context
32
  btn.click(fn=robot_behavior, inputs=[inp], outputs=[out])
33
 
34
  return demo
35
 
36
- # For local testing
37
  if __name__ == "__main__":
38
  app = launch_gradio_app()
39
  app.launch()
 
1
  # gradio_generator.py - CPU & Spaces-compatible Gradio interface for RoboSage
2
+
3
  import gradio as gr
4
  from deployer.simulator_interface import VirtualRobot
5
 
 
6
  def robot_behavior(user_input: str) -> str:
7
  """Bridge between user input and VirtualRobot actions."""
8
  bot = VirtualRobot()
 
10
 
11
  # Greeting detection
12
  if any(greet in text for greet in ["hello", "hi", "hey", "welcome"]):
13
+ return (
14
+ bot.perform_action("wave")
15
+ + "\n"
16
+ + bot.perform_action("say Hello there!")
17
+ )
18
 
19
  # Direct speech command
20
  if text.startswith("say "):
 
23
  # Default fallback
24
  return bot.perform_action("say I'm sorry, I didn't understand that.")
25
 
26
+ def launch_gradio_app(
27
+ title: str = "RoboSage App",
28
+ description: str = "Your robot, your voice."
29
+ ) -> gr.Blocks:
30
+ """Constructs and returns a Gradio Blocks app."""
31
  with gr.Blocks() as demo:
32
  gr.Markdown(f"# 🤖 {title}\n\n{description}")
33
 
34
+ # Define components without trailing commas
35
+ inp = gr.Textbox(
36
+ label="Speak or Type",
37
+ lines=1,
38
+ placeholder="Type or speak your command..."
39
+ )
40
+ out = gr.Textbox(
41
+ label="Robot Response",
42
+ lines=4
43
+ )
44
  btn = gr.Button("Send", key="send-btn")
45
 
46
+ # Wire the click event inside the same Blocks context
47
  btn.click(fn=robot_behavior, inputs=[inp], outputs=[out])
48
 
49
  return demo
50
 
 
51
  if __name__ == "__main__":
52
  app = launch_gradio_app()
53
  app.launch()