mgbam commited on
Commit
00c851e
·
verified ·
1 Parent(s): 5211b7e

Update deployer/gradio_generator.py

Browse files
Files changed (1) hide show
  1. deployer/gradio_generator.py +32 -43
deployer/gradio_generator.py CHANGED
@@ -2,61 +2,50 @@ import gradio as gr
2
  from .simulator_interface import VirtualRobot
3
  import logging
4
 
5
- def create_robot_interface(title="RoboSage", description="Your virtual assistant"):
6
- """Creates the robot interaction interface"""
7
  robot = VirtualRobot()
8
 
9
- def process_command(command):
10
- """Handle user commands with logging"""
11
- logging.info(f"Processing command: {command}")
12
- return robot.perform_action(command)
 
 
 
13
 
14
- # Build interface in atomic operation
15
- with gr.Blocks(title=title) as interface:
16
  gr.Markdown(f"# 🤖 {title}\n\n{description}")
17
 
18
- with gr.Row():
19
- cmd_input = gr.Textbox(
20
- label="Command",
21
- placeholder="Try 'wave' or 'say hello'...",
22
- elem_id="command_input"
23
- )
24
 
25
- with gr.Row():
26
- submit_btn = gr.Button("Submit", variant="primary", elem_id="submit_btn")
27
- clear_btn = gr.Button("Clear", variant="secondary")
28
-
29
- response_output = gr.Textbox(
30
- label="Robot Response",
31
- interactive=False,
32
- elem_id="response_output"
33
- )
34
-
35
- # Event handlers
36
- submit_btn.click(
37
- fn=process_command,
38
- inputs=cmd_input,
39
- outputs=response_output
40
  )
41
 
42
- cmd_input.submit(
43
- fn=process_command,
44
- inputs=cmd_input,
45
- outputs=response_output
 
46
  )
47
 
48
- clear_btn.click(
49
- fn=lambda: ("", ""),
 
50
  inputs=None,
51
- outputs=[cmd_input, response_output]
52
  )
53
 
54
- return interface
55
 
56
  def launch_gradio_app(title="RoboSage", description="Your virtual assistant"):
57
- """Public interface for launching the robot app"""
58
- logging.basicConfig(
59
- level=logging.INFO,
60
- format='%(asctime)s - %(levelname)s - %(message)s'
61
- )
62
- return create_robot_interface(title, description)
 
2
  from .simulator_interface import VirtualRobot
3
  import logging
4
 
5
+ def create_robot_app(title="RoboSage", description="Your virtual assistant"):
6
+ """Creates a fully self-contained robot interface"""
7
  robot = VirtualRobot()
8
 
9
+ def execute_command(command):
10
+ """Process commands with error handling"""
11
+ try:
12
+ return robot.perform_action(command)
13
+ except Exception as e:
14
+ logging.error(f"Command failed: {e}")
15
+ return f"⚠️ Error: {str(e)}"
16
 
17
+ # Build interface in one atomic operation
18
+ with gr.Blocks(title=title) as app:
19
  gr.Markdown(f"# 🤖 {title}\n\n{description}")
20
 
21
+ # Define components and handlers together
22
+ command_box = gr.Textbox(label="Command", placeholder="Try 'wave' or 'say hello'")
23
+ response_box = gr.Textbox(label="Response", interactive=False)
 
 
 
24
 
25
+ # Primary interaction
26
+ gr.Button("Submit").click(
27
+ execute_command,
28
+ inputs=command_box,
29
+ outputs=response_box
 
 
 
 
 
 
 
 
 
 
30
  )
31
 
32
+ # Alternate submission method
33
+ command_box.submit(
34
+ execute_command,
35
+ inputs=command_box,
36
+ outputs=response_box
37
  )
38
 
39
+ # Utility button
40
+ gr.Button("Clear").click(
41
+ lambda: ("", ""),
42
  inputs=None,
43
+ outputs=[command_box, response_box]
44
  )
45
 
46
+ return app
47
 
48
  def launch_gradio_app(title="RoboSage", description="Your virtual assistant"):
49
+ """Public interface that guarantees proper initialization"""
50
+ logging.basicConfig(level=logging.INFO)
51
+ return create_robot_app(title, description)