|
import os |
|
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 generate_app_async(idea: str): |
|
""" |
|
Run the voice-to-app pipeline asynchronously and return a tuple of (status_message, zip_path). |
|
""" |
|
creator = VoiceToAppCreator(idea) |
|
assets = creator.run_pipeline() |
|
title = assets.get("blueprint", {}).get("title", "<unknown>") |
|
zip_path = package_artifacts(assets) |
|
status = f"β
Generated app: {title}" |
|
return status, zip_path |
|
|
|
|
|
def deploy_callback(idea: str): |
|
""" |
|
Synchronous wrapper for Gradio: generates the app and packages it into a ZIP. |
|
Returns (status_message, zip_path). |
|
""" |
|
return asyncio.run(generate_app_async(idea)) |
|
|
|
|
|
def robot_behavior(command: str) -> str: |
|
""" |
|
Simulate robot behavior based on a text command. |
|
""" |
|
return VirtualRobot().perform_action(command) |
|
|
|
|
|
def main(): |
|
""" |
|
Build and launch the Gradio UI for RoboSage. |
|
""" |
|
with gr.Blocks() as demo: |
|
gr.Markdown("# π RoboSage\nGenerate your custom robot app and test it live.") |
|
|
|
with gr.Row(): |
|
|
|
with gr.Column(): |
|
gr.Markdown("## 1οΈβ£ Generate & Download App") |
|
idea_input = gr.Textbox( |
|
label="Your Robot Idea", |
|
placeholder="e.g. A friendly greeting robot.", |
|
lines=2 |
|
) |
|
gen_btn = gr.Button("Generate App") |
|
status_out = gr.Textbox(label="Status", interactive=False) |
|
zip_out = gr.File(label="Download App ZIP") |
|
|
|
gen_btn.click( |
|
fn=deploy_callback, |
|
inputs=[idea_input], |
|
outputs=[status_out, zip_out] |
|
) |
|
|
|
|
|
with gr.Column(): |
|
gr.Markdown("## π€ Robot Simulator") |
|
cmd_input = gr.Textbox( |
|
label="Command", |
|
placeholder="hello or say You rock!", |
|
lines=1 |
|
) |
|
sim_btn = gr.Button("Send") |
|
sim_out = gr.Textbox(label="Robot Response", lines=4, interactive=False) |
|
|
|
sim_btn.click( |
|
fn=robot_behavior, |
|
inputs=[cmd_input], |
|
outputs=[sim_out] |
|
) |
|
|
|
demo.launch( |
|
server_name="0.0.0.0", |
|
server_port=int(os.environ.get("PORT", 7860)), |
|
share=False |
|
) |
|
|
|
if __name__ == "__main__": |
|
main() |
|
|