File size: 2,123 Bytes
67f9d7b
ff11f84
660b656
617d8f7
f69fdac
ff11f84
 
 
 
 
 
 
 
 
 
 
 
 
 
 
617d8f7
ff11f84
 
 
 
1b23b17
 
ff11f84
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
f4f0212
0180e60
ff11f84
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
import os
import asyncio
import gradio as gr
from deployer.gradio_generator import deploy_callback, robot_behavior

# Synchronous wrapper: call the async deploy directly
def generate_app(idea: str):
    """
    Generate the robot app and package to a zip.
    Returns:
      status: str message
      zip_path: str path to zip file or None
    """
    try:
        status, zip_path = asyncio.get_event_loop().run_until_complete(
            deploy_callback(idea)
        )
        return status, zip_path or None
    except Exception as e:
        return f"❌ Failed to generate app: {e}", None

# Build Gradio UI
def main():
    # Define Blocks container
    with gr.Blocks(css=".gradio-container { max-width: 900px; margin: auto; } .section { padding: 1rem; }") 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()