mgbam commited on
Commit
a4d4120
Β·
verified Β·
1 Parent(s): 798d95e

Update deployer/gradio_generator.py

Browse files
Files changed (1) hide show
  1. deployer/gradio_generator.py +30 -23
deployer/gradio_generator.py CHANGED
@@ -1,57 +1,64 @@
1
- # gradio_generator.py
2
- # CPU & Spaces-compatible Gradio interface for RoboSage
3
 
4
  import gradio as gr
5
  from deployer.simulator_interface import VirtualRobot
6
 
 
7
  def robot_behavior(user_input: str) -> str:
8
  """
9
- Bridge between user input and VirtualRobot actions.
10
  """
11
  bot = VirtualRobot()
12
  text = user_input.strip().lower()
13
 
14
- # Greeting detection
15
  if any(greet in text for greet in ["hello", "hi", "hey", "welcome"]):
16
- return (
17
- bot.perform_action("wave")
18
- + "\n"
19
- + bot.perform_action("say Hello there!")
20
- )
21
 
22
  # Direct speech command
23
  if text.startswith("say "):
24
  return bot.perform_action(text)
25
 
26
- # Default fallback
27
  return bot.perform_action("say I'm sorry, I didn't understand that.")
28
 
 
29
  def launch_gradio_app(
30
  title: str = "RoboSage App",
31
  description: str = "Your robot, your voice."
32
  ) -> gr.Blocks:
33
  """
34
- Constructs and returns a Gradio Blocks app.
 
 
35
  """
36
  with gr.Blocks() as demo:
37
  gr.Markdown(f"# πŸ€– {title}\n\n{description}")
38
 
39
- inp = gr.Textbox(
40
- label="Speak or Type",
41
- lines=1,
42
- placeholder="Type or speak your command..."
43
- )
44
- out = gr.Textbox(
45
- label="Robot Response",
46
- lines=4
47
- )
48
- btn = gr.Button("Send", key="send-btn")
49
 
50
- # Wire the click event inside the same Blocks context
51
- btn.click(fn=robot_behavior, inputs=[inp], outputs=[out])
 
 
 
 
 
 
 
52
 
53
  return demo
54
 
 
55
  if __name__ == "__main__":
56
  app = launch_gradio_app()
57
  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
+
7
  def robot_behavior(user_input: str) -> str:
8
  """
9
+ Bridge between user input and VirtualRobot actions with basic NLU.
10
  """
11
  bot = VirtualRobot()
12
  text = user_input.strip().lower()
13
 
14
+ # Greeting detection: wave + greeting
15
  if any(greet in text for greet in ["hello", "hi", "hey", "welcome"]):
16
+ return bot.perform_action("wave") + "\n" + bot.perform_action("say Hello there!")
 
 
 
 
17
 
18
  # Direct speech command
19
  if text.startswith("say "):
20
  return bot.perform_action(text)
21
 
22
+ # Fallback for unrecognized commands
23
  return bot.perform_action("say I'm sorry, I didn't understand that.")
24
 
25
+
26
  def launch_gradio_app(
27
  title: str = "RoboSage App",
28
  description: str = "Your robot, your voice."
29
  ) -> gr.Blocks:
30
  """
31
+ Constructs and returns a Gradio Blocks app with two sections:
32
+ 1. Create your robot app (stubbed)
33
+ 2. Test your robot in simulator
34
  """
35
  with gr.Blocks() as demo:
36
  gr.Markdown(f"# πŸ€– {title}\n\n{description}")
37
 
38
+ # Section: App creation (stubbed)
39
+ with gr.Accordion("🎨 Create your robot app", open=True):
40
+ idea = gr.Textbox(label="Robot Idea", placeholder="e.g. A friendly greeting robot.")
41
+ gen_btn = gr.Button("Generate App", key="gen-app-btn")
42
+ gen_status = gr.Textbox(label="Generation Status", interactive=False)
43
+ gen_btn.click(
44
+ fn=lambda i: "βœ… App generation pipeline executed.",
45
+ inputs=[idea],
46
+ outputs=[gen_status]
47
+ )
48
 
49
+ # Section: Robot simulation
50
+ with gr.Accordion("πŸ€– Test your robot", open=True):
51
+ inp = gr.Textbox(
52
+ label="Speak or Type Command",
53
+ placeholder="Type 'hello' or 'say Have a great day!'"
54
+ )
55
+ out = gr.Textbox(label="Robot Response", lines=4, interactive=False)
56
+ btn = gr.Button("Send", key="simulate-btn")
57
+ btn.click(fn=robot_behavior, inputs=[inp], outputs=[out])
58
 
59
  return demo
60
 
61
+
62
  if __name__ == "__main__":
63
  app = launch_gradio_app()
64
  app.launch()