mgbam commited on
Commit
dd17639
·
verified ·
1 Parent(s): 9ffa70c

Update deployer/gradio_generator.py

Browse files
Files changed (1) hide show
  1. deployer/gradio_generator.py +36 -72
deployer/gradio_generator.py CHANGED
@@ -2,80 +2,44 @@ import gradio as gr
2
  from .simulator_interface import VirtualRobot
3
  import logging
4
 
5
- class RoboSageInterface:
6
- def __init__(self, title="RoboSage", description="Your virtual assistant"):
7
- self.robot = VirtualRobot()
8
- self.title = title
9
- self.description = description
10
- self.logger = logging.getLogger(__name__)
11
- self._setup_logging()
 
 
 
 
 
 
12
 
13
- # Initialize components
14
- self.input_txt = None
15
- self.output_txt = None
16
- self.btn = None
17
-
18
- self.interface = self._create_interface()
19
-
20
- def _setup_logging(self):
21
- logging.basicConfig(
22
- level=logging.INFO,
23
- format='%(asctime)s - %(levelname)s - %(message)s'
24
- )
25
-
26
- def _create_interface(self) -> gr.Blocks:
27
- with gr.Blocks(title=self.title) as interface:
28
- # Store references to components as instance attributes
29
- self._create_components()
30
- self._setup_event_handlers()
31
-
32
- return interface
33
-
34
- def _create_components(self):
35
- """Create and store all interface components"""
36
- gr.Markdown(f"# 🤖 {self.title}\n\n{self.description}")
37
-
38
- with gr.Row():
39
- self.input_txt = gr.Textbox(
40
- label="Command",
41
- placeholder="Try 'wave' or 'say hello'",
42
- elem_id="command_input"
43
- )
44
- self.btn = gr.Button(
45
- "Submit",
46
- variant="primary",
47
- elem_id="submit_btn"
48
- )
49
-
50
- self.output_txt = gr.Textbox(
51
- label="Response",
52
- interactive=False,
53
- elem_id="response_output"
54
- )
55
-
56
- def _setup_event_handlers(self):
57
- """Configure all event handlers"""
58
- def wrapped_process_command(cmd: str) -> str:
59
- self.logger.info(f"Processing command: {cmd}")
60
- return self.robot.perform_action(cmd)
61
-
62
- # Reference components through instance attributes
63
- self.btn.click(
64
- fn=wrapped_process_command,
65
- inputs=self.input_txt,
66
- outputs=self.output_txt
67
  )
68
 
69
- self.input_txt.submit(
70
- fn=wrapped_process_command,
71
- inputs=self.input_txt,
72
- outputs=self.output_txt
 
 
 
 
73
  )
 
 
74
 
75
- def launch_gradio_app(title="RoboSage", description="Your virtual assistant") -> gr.Blocks:
76
- """Public interface for launching the app"""
77
- try:
78
- return RoboSageInterface(title, description).interface
79
- except Exception as e:
80
- logging.critical(f"Failed to create interface: {str(e)}")
81
- raise
 
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()