Update deployer/gradio_generator.py
Browse files- 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
|
6 |
-
"""Creates
|
7 |
robot = VirtualRobot()
|
8 |
|
9 |
-
def
|
10 |
-
"""
|
11 |
-
|
12 |
-
|
|
|
|
|
|
|
13 |
|
14 |
-
# Build interface in atomic operation
|
15 |
-
with gr.Blocks(title=title) as
|
16 |
gr.Markdown(f"# 🤖 {title}\n\n{description}")
|
17 |
|
18 |
-
|
19 |
-
|
20 |
-
|
21 |
-
placeholder="Try 'wave' or 'say hello'...",
|
22 |
-
elem_id="command_input"
|
23 |
-
)
|
24 |
|
25 |
-
|
26 |
-
|
27 |
-
|
28 |
-
|
29 |
-
|
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 |
-
|
43 |
-
|
44 |
-
|
45 |
-
|
|
|
46 |
)
|
47 |
|
48 |
-
|
49 |
-
|
|
|
50 |
inputs=None,
|
51 |
-
outputs=[
|
52 |
)
|
53 |
|
54 |
-
return
|
55 |
|
56 |
def launch_gradio_app(title="RoboSage", description="Your virtual assistant"):
|
57 |
-
"""Public interface
|
58 |
-
logging.basicConfig(
|
59 |
-
|
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)
|
|
|
|
|
|