mgbam commited on
Commit
95277c7
·
verified ·
1 Parent(s): dd17639

Update deployer/gradio_generator.py

Browse files
Files changed (1) hide show
  1. deployer/gradio_generator.py +20 -26
deployer/gradio_generator.py CHANGED
@@ -2,44 +2,38 @@ import gradio as gr
2
  from .simulator_interface import VirtualRobot
3
  import logging
4
 
5
- def create_interface():
6
- """Create interface without any component references"""
7
  robot = VirtualRobot()
8
 
9
  def process_command(command):
10
  return robot.perform_action(command)
11
 
12
- # Build interface in one atomic operation
13
- with gr.Blocks(analytics_enabled=False) as interface:
14
- gr.Markdown("""
15
- # 🤖 RoboSage
16
- ### Your Virtual Healthcare Assistant
17
- """)
18
 
19
- # Define components directly in event handlers
20
- gr.Textbox(
21
- label="Command Input",
22
- placeholder="Try 'wave' or 'say hello'...",
23
- elem_id="command_input"
24
- ).change(
 
25
  process_command,
26
- inputs=gr.Textbox(elem_id="command_input"),
27
- outputs=gr.Textbox(label="Response", elem_id="response_output")
28
  )
29
 
30
- gr.Button(
31
- "Submit",
32
- variant="primary",
33
- elem_id="submit_btn"
34
- ).click(
35
  process_command,
36
- inputs=gr.Textbox(elem_id="command_input"),
37
- outputs=gr.Textbox(elem_id="response_output")
38
  )
39
 
40
  return interface
41
 
42
- def launch_gradio_app():
43
- """Simplified launcher"""
44
  logging.basicConfig(level=logging.INFO)
45
- return create_interface()
 
2
  from .simulator_interface import VirtualRobot
3
  import logging
4
 
5
+ def create_interface(title="RoboSage", description="Your virtual assistant"):
6
+ """Creates interface with configurable title/description"""
7
  robot = VirtualRobot()
8
 
9
  def process_command(command):
10
  return robot.perform_action(command)
11
 
12
+ with gr.Blocks(title=title, analytics_enabled=False) as interface:
13
+ gr.Markdown(f"# 🤖 {title}\n\n{description}")
 
 
 
 
14
 
15
+ # Define components inline
16
+ cmd_input = gr.Textbox(label="Command", placeholder="Try 'wave' or 'say hello'")
17
+ response_output = gr.Textbox(label="Response", interactive=False)
18
+
19
+ # Define button and its handler
20
+ submit_btn = gr.Button("Submit", variant="primary")
21
+ submit_btn.click(
22
  process_command,
23
+ inputs=cmd_input,
24
+ outputs=response_output
25
  )
26
 
27
+ # Also respond to textbox submit
28
+ cmd_input.submit(
 
 
 
29
  process_command,
30
+ inputs=cmd_input,
31
+ outputs=response_output
32
  )
33
 
34
  return interface
35
 
36
+ def launch_gradio_app(**kwargs):
37
+ """Flexible launcher that accepts any parameters"""
38
  logging.basicConfig(level=logging.INFO)
39
+ return create_interface(**kwargs)