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