robosage / deployer /gradio_generator.py
mgbam's picture
Update deployer/gradio_generator.py
1b36f73 verified
Raw History Blame
3.29 kB
# deployer/gradio_generator.py
import asyncio
import gradio as gr
from core_creator.voice_to_app import VoiceToAppCreator
from deployer.simulator_interface import VirtualRobot
from deployer.revenue_tracker import package_artifacts
async def _run_pipeline(idea: str) -> str:
"""
Asynchronously run the voice→app pipeline and return a status message.
"""
creator = VoiceToAppCreator(idea)
assets = creator.run_pipeline()
title = assets.get("blueprint", {}).get("title", "<unknown>")
return f"βœ… Generated app: {title}"
def deploy_callback(idea: str) -> str:
"""
Synchronous wrapper for Gradio: generate the app.
"""
return asyncio.run(_run_pipeline(idea))
def robot_behavior(user_input: str) -> str:
"""
Simulate robot action based on a user command.
"""
return VirtualRobot().perform_action(user_input)
def download_callback() -> str:
"""
Package all generated app artifacts into a ZIP and return its file path.
"""
zip_path = package_artifacts()
return zip_path
def launch_gradio_app() -> gr.Blocks:
"""
Build and return the Gradio interface.
"""
demo = gr.Blocks()
with demo:
gr.Markdown(
"## πŸš€ RoboSage \n"
"Generate your custom robot app and test it live."
)
with gr.Row():
# β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”
# 1️⃣ Generate App + Download ZIP
# β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”
with gr.Column(scale=1):
gr.Markdown("### 1️⃣ Generate App")
idea_input = gr.Textbox(
label="Your Robot Idea",
placeholder="e.g. A friendly greeting robot."
)
gen_btn = gr.Button("Generate App")
status_out = gr.Textbox(label="Status", interactive=False)
gen_btn.click(
fn=deploy_callback,
inputs=[idea_input],
outputs=[status_out]
)
download_btn = gr.Button("πŸ“¦ Download App ZIP")
zip_out = gr.File(label="Your App ZIP")
download_btn.click(
fn=download_callback,
outputs=[zip_out]
)
# β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”
# 2️⃣ Robot Simulator
# β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”
with gr.Column(scale=1):
gr.Markdown("### 2️⃣ Robot Simulator")
cmd_input = gr.Textbox(
label="Speak or Type Command",
placeholder="hello or say You rock!"
)
send_btn = gr.Button("Send")
resp_out = gr.Textbox(label="Robot Response", lines=4, interactive=False)
send_btn.click(
fn=robot_behavior,
inputs=[cmd_input],
outputs=[resp_out]
)
return demo
if __name__ == "__main__":
launch_gradio_app().launch()