Update deployer/gradio_generator.py
Browse files- 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 |
-
"""
|
7 |
robot = VirtualRobot()
|
8 |
|
9 |
def process_command(command):
|
10 |
return robot.perform_action(command)
|
11 |
|
12 |
-
|
13 |
-
|
14 |
-
gr.Markdown("""
|
15 |
-
# 🤖 RoboSage
|
16 |
-
### Your Virtual Healthcare Assistant
|
17 |
-
""")
|
18 |
|
19 |
-
# Define components
|
20 |
-
gr.Textbox(
|
21 |
-
|
22 |
-
|
23 |
-
|
24 |
-
|
|
|
25 |
process_command,
|
26 |
-
inputs=
|
27 |
-
outputs=
|
28 |
)
|
29 |
|
30 |
-
|
31 |
-
|
32 |
-
variant="primary",
|
33 |
-
elem_id="submit_btn"
|
34 |
-
).click(
|
35 |
process_command,
|
36 |
-
inputs=
|
37 |
-
outputs=
|
38 |
)
|
39 |
|
40 |
return interface
|
41 |
|
42 |
-
def launch_gradio_app():
|
43 |
-
"""
|
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)
|