Update deployer/gradio_generator.py
Browse files- deployer/gradio_generator.py +17 -14
deployer/gradio_generator.py
CHANGED
|
@@ -6,39 +6,40 @@ 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 |
-
#
|
| 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 |
-
#
|
| 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"
|
| 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
|
| 32 |
def launch_gradio_app():
|
| 33 |
css = r"""
|
| 34 |
.gradio-container { max-width: 800px; margin: auto; }
|
| 35 |
-
.
|
| 36 |
"""
|
| 37 |
|
| 38 |
with gr.Blocks(css=css) as demo:
|
| 39 |
-
gr.Markdown("# π RoboSage
|
|
|
|
| 40 |
|
| 41 |
-
|
|
|
|
| 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")
|
|
@@ -46,14 +47,16 @@ def launch_gradio_app():
|
|
| 46 |
|
| 47 |
gen_btn.click(fn=generate_app, inputs=[idea_input], outputs=[status_out])
|
| 48 |
|
| 49 |
-
|
|
|
|
| 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 |
-
|
|
|
|
| 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")
|
|
@@ -69,6 +72,6 @@ def launch_gradio_app():
|
|
| 69 |
|
| 70 |
return demo
|
| 71 |
|
| 72 |
-
# Expose for import
|
| 73 |
-
robot_behavior
|
| 74 |
-
launch_gradio_app
|
|
|
|
| 6 |
from deployer.simulator_interface import VirtualRobot
|
| 7 |
from deployer.revenue_tracker import package_artifacts
|
| 8 |
|
| 9 |
+
# --- Async pipeline runner ---
|
| 10 |
async def _run_pipeline_async(idea: str) -> str:
|
| 11 |
creator = VoiceToAppCreator(idea)
|
| 12 |
assets = creator.run_pipeline()
|
| 13 |
+
# blueprint title fallback
|
| 14 |
return assets.get("blueprint", {}).get("title", "<unknown>")
|
| 15 |
|
| 16 |
+
# --- Sync wrappers for Gradio ---
|
| 17 |
def generate_app(idea: str) -> str:
|
| 18 |
title = asyncio.run(_run_pipeline_async(idea))
|
| 19 |
return f"β
Generated app: {title}"
|
| 20 |
|
|
|
|
| 21 |
def get_app_zip() -> str:
|
| 22 |
zip_path = package_artifacts()
|
| 23 |
if not os.path.isfile(zip_path):
|
| 24 |
+
raise FileNotFoundError(f"Could not find ZIP at {zip_path}")
|
| 25 |
return zip_path
|
| 26 |
|
|
|
|
| 27 |
def robot_behavior(command: str) -> str:
|
| 28 |
return VirtualRobot().perform_action(command)
|
| 29 |
|
| 30 |
+
# --- Build & launch Gradio UI ---
|
| 31 |
def launch_gradio_app():
|
| 32 |
css = r"""
|
| 33 |
.gradio-container { max-width: 800px; margin: auto; }
|
| 34 |
+
.gradio-box { padding: 1em; margin-bottom: 2em; border: 1px solid #e2e2e2; border-radius: 8px; }
|
| 35 |
"""
|
| 36 |
|
| 37 |
with gr.Blocks(css=css) as demo:
|
| 38 |
+
gr.Markdown("# π RoboSage")
|
| 39 |
+
gr.Markdown("Generate your custom robot app and test it live.")
|
| 40 |
|
| 41 |
+
# Generate App section
|
| 42 |
+
with gr.Box(elem_id="generate-app", css_class="gradio-box"):
|
| 43 |
gr.Markdown("## 1οΈβ£ Generate App")
|
| 44 |
idea_input = gr.Textbox(label="Your Robot Idea", placeholder="e.g. A friendly greeting robot", lines=1)
|
| 45 |
gen_btn = gr.Button("Generate App")
|
|
|
|
| 47 |
|
| 48 |
gen_btn.click(fn=generate_app, inputs=[idea_input], outputs=[status_out])
|
| 49 |
|
| 50 |
+
# Download ZIP section
|
| 51 |
+
with gr.Box(elem_id="download-app", css_class="gradio-box"):
|
| 52 |
gr.Markdown("## π¦ Download Packaged App")
|
| 53 |
dl_btn = gr.Button("Download App ZIP")
|
| 54 |
dl_file = gr.File(label="App ZIP File")
|
| 55 |
|
| 56 |
dl_btn.click(fn=get_app_zip, inputs=None, outputs=[dl_file])
|
| 57 |
|
| 58 |
+
# Simulator section
|
| 59 |
+
with gr.Box(elem_id="robot-sim", css_class="gradio-box"):
|
| 60 |
gr.Markdown("## 2οΈβ£ Robot Simulator")
|
| 61 |
cmd_input = gr.Textbox(label="Command", placeholder="hello or say You rock!", lines=1)
|
| 62 |
sim_btn = gr.Button("Send")
|
|
|
|
| 72 |
|
| 73 |
return demo
|
| 74 |
|
| 75 |
+
# Expose for external import
|
| 76 |
+
robot_behavior = robot_behavior
|
| 77 |
+
launch_gradio_app = launch_gradio_app
|