Update deployer/gradio_generator.py
Browse files- deployer/gradio_generator.py +48 -27
deployer/gradio_generator.py
CHANGED
@@ -1,65 +1,86 @@
|
|
|
|
|
|
1 |
import gradio as gr
|
2 |
from core_creator.voice_to_app import VoiceToAppCreator
|
3 |
from deployer.simulator_interface import VirtualRobot
|
4 |
from deployer.revenue_tracker import package_artifacts
|
5 |
|
6 |
-
def
|
7 |
"""
|
8 |
-
|
9 |
-
Returns a status message and the path to the ZIP file.
|
10 |
"""
|
11 |
creator = VoiceToAppCreator(idea)
|
12 |
assets = creator.run_pipeline()
|
13 |
title = assets.get("blueprint", {}).get("title", "<unknown>")
|
14 |
zip_path = package_artifacts(assets)
|
15 |
-
|
16 |
-
return
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
17 |
|
18 |
def robot_behavior(command: str) -> str:
|
19 |
"""
|
20 |
-
|
21 |
"""
|
22 |
return VirtualRobot().perform_action(command)
|
23 |
|
|
|
24 |
def launch_gradio_app():
|
25 |
"""
|
26 |
-
|
|
|
|
|
|
|
|
|
27 |
"""
|
28 |
-
|
29 |
-
|
|
|
|
|
30 |
|
31 |
with gr.Row():
|
32 |
with gr.Column():
|
33 |
-
gr.Markdown("
|
34 |
idea_input = gr.Textbox(
|
35 |
-
label="
|
36 |
-
placeholder="e.g
|
37 |
lines=2
|
38 |
)
|
39 |
-
|
40 |
-
|
41 |
-
|
42 |
|
43 |
-
|
44 |
fn=deploy_callback,
|
45 |
-
inputs=idea_input,
|
46 |
-
outputs=[
|
47 |
)
|
48 |
|
49 |
with gr.Column():
|
50 |
-
gr.Markdown("
|
51 |
-
|
52 |
-
label="
|
53 |
-
placeholder="
|
54 |
lines=1
|
55 |
)
|
56 |
-
|
57 |
-
|
58 |
|
59 |
-
|
60 |
fn=robot_behavior,
|
61 |
-
inputs=
|
62 |
-
outputs=
|
63 |
)
|
64 |
|
65 |
return demo
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import os
|
2 |
+
import asyncio
|
3 |
import gradio as gr
|
4 |
from core_creator.voice_to_app import VoiceToAppCreator
|
5 |
from deployer.simulator_interface import VirtualRobot
|
6 |
from deployer.revenue_tracker import package_artifacts
|
7 |
|
8 |
+
async def _generate_app_async(idea: str):
|
9 |
"""
|
10 |
+
Run the VoiceToApp pipeline asynchronously and return status + ZIP path.
|
|
|
11 |
"""
|
12 |
creator = VoiceToAppCreator(idea)
|
13 |
assets = creator.run_pipeline()
|
14 |
title = assets.get("blueprint", {}).get("title", "<unknown>")
|
15 |
zip_path = package_artifacts(assets)
|
16 |
+
status = f"β
Generated app: {title}"
|
17 |
+
return status, zip_path
|
18 |
+
|
19 |
+
|
20 |
+
def deploy_callback(idea: str):
|
21 |
+
"""
|
22 |
+
Synchronous wrapper for Gradio: generate and package app.
|
23 |
+
"""
|
24 |
+
return asyncio.run(_generate_app_async(idea))
|
25 |
+
|
26 |
|
27 |
def robot_behavior(command: str) -> str:
|
28 |
"""
|
29 |
+
Simulate robot action based on a text command.
|
30 |
"""
|
31 |
return VirtualRobot().perform_action(command)
|
32 |
|
33 |
+
|
34 |
def launch_gradio_app():
|
35 |
"""
|
36 |
+
Build and return the Gradio Blocks UI for the RoboSage app.
|
37 |
+
"""
|
38 |
+
css = r"""
|
39 |
+
.gradio-container { max-width: 900px; margin: auto; }
|
40 |
+
.section { padding: 1rem; }
|
41 |
"""
|
42 |
+
|
43 |
+
demo = gr.Blocks(css=css)
|
44 |
+
with demo:
|
45 |
+
gr.Markdown("# π RoboSage\nGenerate and simulate your custom robot app.")
|
46 |
|
47 |
with gr.Row():
|
48 |
with gr.Column():
|
49 |
+
gr.Markdown("## π οΈ Generate & Download App")
|
50 |
idea_input = gr.Textbox(
|
51 |
+
label="Robot Idea",
|
52 |
+
placeholder="e.g. A friendly greeting robot.",
|
53 |
lines=2
|
54 |
)
|
55 |
+
gen_btn = gr.Button("Generate App")
|
56 |
+
status_out = gr.Textbox(label="Status", interactive=False)
|
57 |
+
zip_out = gr.File(label="Download App ZIP")
|
58 |
|
59 |
+
gen_btn.click(
|
60 |
fn=deploy_callback,
|
61 |
+
inputs=[idea_input],
|
62 |
+
outputs=[status_out, zip_out]
|
63 |
)
|
64 |
|
65 |
with gr.Column():
|
66 |
+
gr.Markdown("## π€ Robot Simulator")
|
67 |
+
cmd_input = gr.Textbox(
|
68 |
+
label="Command",
|
69 |
+
placeholder="hello or say You rock!",
|
70 |
lines=1
|
71 |
)
|
72 |
+
sim_btn = gr.Button("Send")
|
73 |
+
sim_out = gr.Textbox(label="Robot Response", lines=4, interactive=False)
|
74 |
|
75 |
+
sim_btn.click(
|
76 |
fn=robot_behavior,
|
77 |
+
inputs=[cmd_input],
|
78 |
+
outputs=[sim_out]
|
79 |
)
|
80 |
|
81 |
return demo
|
82 |
+
|
83 |
+
|
84 |
+
if __name__ == "__main__":
|
85 |
+
demo = launch_gradio_app()
|
86 |
+
demo.launch(server_name="0.0.0.0", server_port=int(os.environ.get("PORT", 7860)), share=False)
|