Update deployer/gradio_generator.py
Browse files- deployer/gradio_generator.py +36 -52
deployer/gradio_generator.py
CHANGED
@@ -1,90 +1,74 @@
|
|
1 |
-
import asyncio
|
2 |
import os
|
3 |
-
import
|
4 |
import gradio as gr
|
5 |
|
6 |
from core_creator.voice_to_app import VoiceToAppCreator
|
7 |
from deployer.simulator_interface import VirtualRobot
|
8 |
from deployer.revenue_tracker import package_artifacts
|
9 |
|
10 |
-
#
|
11 |
-
async def
|
12 |
creator = VoiceToAppCreator(idea)
|
13 |
assets = creator.run_pipeline()
|
14 |
-
|
15 |
-
return title
|
16 |
|
17 |
# Synchronous wrapper for Gradio
|
18 |
def generate_app(idea: str) -> str:
|
19 |
-
title = asyncio.run(
|
20 |
return f"β
Generated app: {title}"
|
21 |
|
22 |
-
# Package artifacts into a ZIP and return
|
23 |
def get_app_zip() -> str:
|
24 |
-
# package_artifacts should return the absolute path to the ZIP
|
25 |
zip_path = package_artifacts()
|
26 |
if not os.path.isfile(zip_path):
|
27 |
-
raise FileNotFoundError(f"
|
28 |
return zip_path
|
29 |
|
30 |
-
# Simulated robot behavior
|
31 |
def robot_behavior(command: str) -> str:
|
32 |
return VirtualRobot().perform_action(command)
|
33 |
|
34 |
-
#
|
35 |
def launch_gradio_app():
|
36 |
-
|
37 |
-
|
|
|
|
|
|
|
|
|
38 |
gr.Markdown("# π RoboSage\nGenerate your custom robot app and test it live.")
|
39 |
|
40 |
-
with gr.
|
41 |
gr.Markdown("## 1οΈβ£ Generate App")
|
42 |
-
idea_input = gr.Textbox(
|
43 |
-
|
44 |
-
|
45 |
-
|
46 |
-
)
|
47 |
-
|
48 |
-
|
49 |
-
|
50 |
-
gen_btn.click(
|
51 |
-
fn=generate_app,
|
52 |
-
inputs=[idea_input],
|
53 |
-
outputs=[status_output]
|
54 |
-
)
|
55 |
-
|
56 |
-
with gr.Group(elem_id="download-app"), gr.Box():
|
57 |
gr.Markdown("## π¦ Download Packaged App")
|
58 |
-
dl_btn
|
59 |
dl_file = gr.File(label="App ZIP File")
|
60 |
|
61 |
-
dl_btn.click(
|
62 |
-
fn=get_app_zip,
|
63 |
-
inputs=None,
|
64 |
-
outputs=[dl_file]
|
65 |
-
)
|
66 |
|
67 |
-
with gr.
|
68 |
gr.Markdown("## 2οΈβ£ Robot Simulator")
|
69 |
-
cmd_input
|
70 |
-
|
71 |
-
placeholder="hello or say You rock!",
|
72 |
-
lines=1
|
73 |
-
)
|
74 |
-
sim_btn = gr.Button("Send")
|
75 |
sim_output = gr.Textbox(label="Robot Response", lines=4, interactive=False)
|
76 |
|
77 |
-
sim_btn.click(
|
78 |
-
fn=robot_behavior,
|
79 |
-
inputs=[cmd_input],
|
80 |
-
outputs=[sim_output]
|
81 |
-
)
|
82 |
|
83 |
-
demo.launch(
|
|
|
|
|
|
|
|
|
84 |
|
85 |
return demo
|
86 |
|
87 |
-
|
88 |
-
|
89 |
-
robot_behavior = robot_behavior
|
90 |
launch_gradio_app = launch_gradio_app
|
|
|
|
|
1 |
import os
|
2 |
+
import asyncio
|
3 |
import gradio as gr
|
4 |
|
5 |
from core_creator.voice_to_app import VoiceToAppCreator
|
6 |
from deployer.simulator_interface import VirtualRobot
|
7 |
from deployer.revenue_tracker import package_artifacts
|
8 |
|
9 |
+
# Asynchronous pipeline runner
|
10 |
+
async def _run_pipeline_async(idea: str) -> str:
|
11 |
creator = VoiceToAppCreator(idea)
|
12 |
assets = creator.run_pipeline()
|
13 |
+
return assets.get("blueprint", {}).get("title", "<unknown>")
|
|
|
14 |
|
15 |
# Synchronous wrapper for Gradio
|
16 |
def generate_app(idea: str) -> str:
|
17 |
+
title = asyncio.run(_run_pipeline_async(idea))
|
18 |
return f"β
Generated app: {title}"
|
19 |
|
20 |
+
# Package the last-generated artifacts into a ZIP and return its path
|
21 |
def get_app_zip() -> str:
|
|
|
22 |
zip_path = package_artifacts()
|
23 |
if not os.path.isfile(zip_path):
|
24 |
+
raise FileNotFoundError(f"ZIP not found at {zip_path}")
|
25 |
return zip_path
|
26 |
|
27 |
+
# Simulated robot behavior endpoint
|
28 |
def robot_behavior(command: str) -> str:
|
29 |
return VirtualRobot().perform_action(command)
|
30 |
|
31 |
+
# Build and launch the Gradio interface
|
32 |
def launch_gradio_app():
|
33 |
+
css = r"""
|
34 |
+
.gradio-container { max-width: 800px; margin: auto; }
|
35 |
+
.section { margin-bottom: 2em; }
|
36 |
+
"""
|
37 |
+
|
38 |
+
with gr.Blocks(css=css) as demo:
|
39 |
gr.Markdown("# π RoboSage\nGenerate your custom robot app and test it live.")
|
40 |
|
41 |
+
with gr.Box(elem_id="generate-app", variant="panel"):
|
42 |
gr.Markdown("## 1οΈβ£ Generate App")
|
43 |
+
idea_input = gr.Textbox(label="Your Robot Idea", placeholder="e.g. A friendly greeting robot", lines=1)
|
44 |
+
gen_btn = gr.Button("Generate App")
|
45 |
+
status_out = gr.Textbox(label="Status", interactive=False)
|
46 |
+
|
47 |
+
gen_btn.click(fn=generate_app, inputs=[idea_input], outputs=[status_out])
|
48 |
+
|
49 |
+
with gr.Box(elem_id="download-app", variant="panel"):
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
50 |
gr.Markdown("## π¦ Download Packaged App")
|
51 |
+
dl_btn = gr.Button("Download App ZIP")
|
52 |
dl_file = gr.File(label="App ZIP File")
|
53 |
|
54 |
+
dl_btn.click(fn=get_app_zip, inputs=None, outputs=[dl_file])
|
|
|
|
|
|
|
|
|
55 |
|
56 |
+
with gr.Box(elem_id="robot-sim", variant="panel"):
|
57 |
gr.Markdown("## 2οΈβ£ Robot Simulator")
|
58 |
+
cmd_input = gr.Textbox(label="Command", placeholder="hello or say You rock!", lines=1)
|
59 |
+
sim_btn = gr.Button("Send")
|
|
|
|
|
|
|
|
|
60 |
sim_output = gr.Textbox(label="Robot Response", lines=4, interactive=False)
|
61 |
|
62 |
+
sim_btn.click(fn=robot_behavior, inputs=[cmd_input], outputs=[sim_output])
|
|
|
|
|
|
|
|
|
63 |
|
64 |
+
demo.launch(
|
65 |
+
server_name="0.0.0.0",
|
66 |
+
server_port=int(os.environ.get("PORT", 7860)),
|
67 |
+
share=False
|
68 |
+
)
|
69 |
|
70 |
return demo
|
71 |
|
72 |
+
# Expose for import
|
73 |
+
robot_behavior = robot_behavior
|
|
|
74 |
launch_gradio_app = launch_gradio_app
|