|
import os |
|
import gradio as gr |
|
from deployer.gradio_generator import deploy_callback, robot_behavior |
|
|
|
def generate_app(idea: str): |
|
""" |
|
Gradio callback: returns (status_message, path_to_zip). |
|
Gradio's File component will serve the zip. |
|
""" |
|
return deploy_callback(idea) |
|
|
|
def main(): |
|
with gr.Blocks() as demo: |
|
gr.Markdown("# 🚀 RoboSage\nGenerate & download a simple robot app, then 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 & ZIP") |
|
status_out = gr.Textbox(label="Status", interactive=False) |
|
zip_out = gr.File(label="Download App ZIP") |
|
|
|
gen_btn.click( |
|
fn=generate_app, |
|
inputs=[idea_input], |
|
outputs=[status_out, zip_out], |
|
) |
|
|
|
|
|
with gr.Column(): |
|
gr.Markdown("## 2️⃣ Robot Simulator") |
|
cmd_input = gr.Textbox( |
|
label="Command", |
|
placeholder="say 'hello' or 'You rock!'", |
|
lines=1, |
|
) |
|
sim_btn = gr.Button("Send Command") |
|
sim_out = gr.Textbox(label="Robot Response", 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() |
|
|