mgbam commited on
Commit
9d9cd27
·
verified ·
1 Parent(s): cad7bdc

Update deployer/gradio_generator.py

Browse files
Files changed (1) hide show
  1. deployer/gradio_generator.py +11 -13
deployer/gradio_generator.py CHANGED
@@ -1,9 +1,9 @@
1
- # gradio_generator.py - Wraps robot behavior and simulator into Gradio interface
2
 
3
  import gradio as gr
4
  from deployer.simulator_interface import VirtualRobot
5
 
6
- # The logic that interprets voice or text and maps it to robot actions
7
  def robot_behavior(user_input: str):
8
  bot = VirtualRobot()
9
  user_input = user_input.lower().strip()
@@ -15,22 +15,20 @@ def robot_behavior(user_input: str):
15
  else:
16
  return bot.perform_action("say I didn't understand that. Try again!")
17
 
18
- # Generate Gradio app dynamically
19
  def launch_gradio_app(title="RoboSage App", description="Your robot, your voice."):
20
- with gr.Blocks() as demo:
21
- gr.Markdown(f"""# 🤖 {title}
22
- {description}
23
- """)
24
- with gr.Row():
25
  inp = gr.Textbox(label="Speak or Type")
26
  out = gr.Textbox(label="Robot Response")
27
- btn = gr.Button("Send")
 
 
28
 
29
- btn.click(fn=robot_behavior, inputs=inp, outputs=out)
30
 
31
- return demo
32
-
33
- # For testing
34
  if __name__ == "__main__":
35
  app = launch_gradio_app()
36
  app.launch()
 
1
+ # gradio_generator.py - Safe version for Hugging Face Spaces
2
 
3
  import gradio as gr
4
  from deployer.simulator_interface import VirtualRobot
5
 
6
+ # Logic that interprets voice or text and maps it to robot actions
7
  def robot_behavior(user_input: str):
8
  bot = VirtualRobot()
9
  user_input = user_input.lower().strip()
 
15
  else:
16
  return bot.perform_action("say I didn't understand that. Try again!")
17
 
18
+ # Generate Gradio app
19
  def launch_gradio_app(title="RoboSage App", description="Your robot, your voice."):
20
+ def create_ui():
21
+ with gr.Blocks() as demo:
22
+ gr.Markdown(f"# 🤖 {title}\n{description}")
 
 
23
  inp = gr.Textbox(label="Speak or Type")
24
  out = gr.Textbox(label="Robot Response")
25
+ btn = gr.Button("Send")
26
+ btn.click(fn=robot_behavior, inputs=inp, outputs=out)
27
+ return demo
28
 
29
+ return create_ui()
30
 
31
+ # Run directly
 
 
32
  if __name__ == "__main__":
33
  app = launch_gradio_app()
34
  app.launch()