Update deployer/gradio_generator.py
Browse files- deployer/gradio_generator.py +38 -15
deployer/gradio_generator.py
CHANGED
@@ -2,38 +2,61 @@ import gradio as gr
|
|
2 |
from .simulator_interface import VirtualRobot
|
3 |
import logging
|
4 |
|
5 |
-
def
|
6 |
-
"""Creates
|
7 |
robot = VirtualRobot()
|
8 |
|
9 |
def process_command(command):
|
|
|
|
|
10 |
return robot.perform_action(command)
|
11 |
|
12 |
-
|
|
|
13 |
gr.Markdown(f"# 🤖 {title}\n\n{description}")
|
14 |
|
15 |
-
|
16 |
-
|
17 |
-
|
|
|
|
|
|
|
18 |
|
19 |
-
|
20 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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(
|
37 |
-
"""
|
38 |
-
logging.basicConfig(
|
39 |
-
|
|
|
|
|
|
|
|
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)
|