Update deployer/gradio_generator.py
Browse files- deployer/gradio_generator.py +28 -26
deployer/gradio_generator.py
CHANGED
@@ -2,50 +2,52 @@ import gradio as gr
|
|
2 |
from .simulator_interface import VirtualRobot
|
3 |
import logging
|
4 |
|
5 |
-
def
|
6 |
-
"""Creates a
|
7 |
robot = VirtualRobot()
|
8 |
|
9 |
-
|
10 |
-
|
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
|
19 |
gr.Markdown(f"# 🤖 {title}\n\n{description}")
|
20 |
|
21 |
-
#
|
22 |
-
|
23 |
-
|
|
|
|
|
24 |
|
25 |
-
|
26 |
-
|
27 |
-
|
28 |
-
|
29 |
-
|
|
|
|
|
30 |
)
|
31 |
|
32 |
-
|
33 |
-
|
34 |
-
|
35 |
-
|
36 |
-
outputs=response_box
|
37 |
)
|
38 |
|
39 |
-
|
40 |
-
|
41 |
-
lambda: ("", ""),
|
42 |
inputs=None,
|
43 |
-
outputs=[
|
44 |
)
|
45 |
|
46 |
-
return
|
47 |
|
48 |
def launch_gradio_app(title="RoboSage", description="Your virtual assistant"):
|
49 |
-
"""Public interface that
|
50 |
logging.basicConfig(level=logging.INFO)
|
51 |
-
return
|
|
|
2 |
from .simulator_interface import VirtualRobot
|
3 |
import logging
|
4 |
|
5 |
+
def build_robot_interface(title="RoboSage", description="Your virtual assistant"):
|
6 |
+
"""Creates a completely self-contained interface without external references"""
|
7 |
robot = VirtualRobot()
|
8 |
|
9 |
+
# Define all processing logic first
|
10 |
+
def process_command(command):
|
11 |
try:
|
12 |
return robot.perform_action(command)
|
13 |
except Exception as e:
|
14 |
+
logging.error(f"Command processing failed: {e}")
|
15 |
return f"⚠️ Error: {str(e)}"
|
16 |
|
17 |
# Build interface in one atomic operation
|
18 |
+
with gr.Blocks(title=title) as interface:
|
19 |
gr.Markdown(f"# 🤖 {title}\n\n{description}")
|
20 |
|
21 |
+
# Create and use components immediately in the same context
|
22 |
+
with gr.Row():
|
23 |
+
input_box = gr.Textbox(label="Command", placeholder="Try 'wave' or 'say hello'")
|
24 |
+
submit_btn = gr.Button("Submit", variant="primary")
|
25 |
+
clear_btn = gr.Button("Clear")
|
26 |
|
27 |
+
output_box = gr.Textbox(label="Response", interactive=False)
|
28 |
+
|
29 |
+
# Define all event handlers in the same context
|
30 |
+
submit_btn.click(
|
31 |
+
fn=process_command,
|
32 |
+
inputs=input_box,
|
33 |
+
outputs=output_box
|
34 |
)
|
35 |
|
36 |
+
input_box.submit(
|
37 |
+
fn=process_command,
|
38 |
+
inputs=input_box,
|
39 |
+
outputs=output_box
|
|
|
40 |
)
|
41 |
|
42 |
+
clear_btn.click(
|
43 |
+
fn=lambda: ("", ""),
|
|
|
44 |
inputs=None,
|
45 |
+
outputs=[input_box, output_box]
|
46 |
)
|
47 |
|
48 |
+
return interface
|
49 |
|
50 |
def launch_gradio_app(title="RoboSage", description="Your virtual assistant"):
|
51 |
+
"""Public interface that ensures proper initialization"""
|
52 |
logging.basicConfig(level=logging.INFO)
|
53 |
+
return build_robot_interface(title, description)
|