Update app.py
Browse files
app.py
CHANGED
@@ -1,56 +1,53 @@
|
|
1 |
import os
|
|
|
2 |
import gradio as gr
|
3 |
-
|
4 |
from deployer.gradio_generator import deploy_callback, robot_behavior
|
5 |
|
6 |
-
|
7 |
-
|
8 |
-
|
9 |
-
|
10 |
-
|
11 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
12 |
|
|
|
|
|
|
|
|
|
13 |
gr.Markdown("# 🚀 RoboSage\nGenerate & download a simple robot app, then test it live.")
|
14 |
|
15 |
-
with gr.
|
16 |
-
gr.
|
17 |
-
|
18 |
-
label="Your Robot Idea",
|
19 |
-
|
20 |
-
|
21 |
-
|
22 |
-
|
23 |
-
|
24 |
-
|
25 |
-
|
26 |
-
|
27 |
-
|
28 |
-
|
29 |
-
|
30 |
-
|
31 |
-
|
32 |
-
|
33 |
-
|
34 |
-
|
35 |
-
|
36 |
-
|
37 |
-
|
38 |
-
)
|
39 |
-
sim_btn = gr.Button("Send Command")
|
40 |
-
sim_out = gr.Textbox(label="Robot Response", interactive=False)
|
41 |
-
|
42 |
-
sim_btn.click(
|
43 |
-
fn=robot_behavior,
|
44 |
-
inputs=[cmd_input],
|
45 |
-
outputs=[sim_out]
|
46 |
-
)
|
47 |
-
|
48 |
-
# Launch
|
49 |
-
demo.launch(
|
50 |
-
server_name="0.0.0.0",
|
51 |
-
server_port=int(os.environ.get("PORT", 7860)),
|
52 |
-
share=False
|
53 |
-
)
|
54 |
|
55 |
if __name__ == "__main__":
|
56 |
-
main()
|
|
|
1 |
import os
|
2 |
+
import asyncio
|
3 |
import gradio as gr
|
|
|
4 |
from deployer.gradio_generator import deploy_callback, robot_behavior
|
5 |
|
6 |
+
# Synchronous wrapper: call the async deploy directly
|
7 |
+
def generate_app(idea: str):
|
8 |
+
"""
|
9 |
+
Generate the robot app and package to a zip.
|
10 |
+
Returns:
|
11 |
+
status: str message
|
12 |
+
zip_path: str path to zip file or None
|
13 |
+
"""
|
14 |
+
try:
|
15 |
+
status, zip_path = asyncio.get_event_loop().run_until_complete(
|
16 |
+
deploy_callback(idea)
|
17 |
+
)
|
18 |
+
return status, zip_path or None
|
19 |
+
except Exception as e:
|
20 |
+
return f"❌ Failed to generate app: {e}", None
|
21 |
|
22 |
+
# Build Gradio UI
|
23 |
+
def main():
|
24 |
+
# Define Blocks container
|
25 |
+
with gr.Blocks(css=".gradio-container { max-width: 900px; margin: auto; } .section { padding: 1rem; }") as demo:
|
26 |
gr.Markdown("# 🚀 RoboSage\nGenerate & download a simple robot app, then test it live.")
|
27 |
|
28 |
+
with gr.Row():
|
29 |
+
with gr.Column():
|
30 |
+
gr.Markdown("## 1️⃣ Generate & Download App")
|
31 |
+
idea_input = gr.Textbox(label="Your Robot Idea", placeholder="e.g. A friendly greeting robot", lines=2)
|
32 |
+
gen_btn = gr.Button("Generate App & ZIP")
|
33 |
+
status_out = gr.Textbox(label="Status", interactive=False)
|
34 |
+
zip_out = gr.File(label="Download App ZIP")
|
35 |
+
gen_btn.click(fn=generate_app,
|
36 |
+
inputs=[idea_input],
|
37 |
+
outputs=[status_out, zip_out])
|
38 |
+
|
39 |
+
with gr.Column():
|
40 |
+
gr.Markdown("## 2️⃣ Robot Simulator")
|
41 |
+
cmd_input = gr.Textbox(label="Command", placeholder="say 'hello' or 'You rock!'", lines=1)
|
42 |
+
sim_btn = gr.Button("Send Command")
|
43 |
+
sim_out = gr.Textbox(label="Robot Response", interactive=False)
|
44 |
+
sim_btn.click(fn=robot_behavior,
|
45 |
+
inputs=[cmd_input],
|
46 |
+
outputs=[sim_out])
|
47 |
+
|
48 |
+
demo.launch(server_name="0.0.0.0",
|
49 |
+
server_port=int(os.environ.get("PORT", 7860)),
|
50 |
+
share=False)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
51 |
|
52 |
if __name__ == "__main__":
|
53 |
+
main()
|