Update app.py
Browse files
app.py
CHANGED
@@ -1,54 +1,42 @@
|
|
1 |
-
|
2 |
-
|
3 |
import gradio as gr
|
4 |
-
from deployer.gradio_generator import deploy_callback, robot_behavior
|
|
|
|
|
|
|
|
|
5 |
|
6 |
-
|
7 |
-
|
8 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
9 |
|
10 |
with gr.Row():
|
11 |
-
with gr.Column():
|
12 |
-
gr.Markdown("
|
13 |
-
idea_input = gr.Textbox(
|
14 |
-
|
15 |
-
|
16 |
-
|
17 |
-
|
18 |
-
|
19 |
-
|
20 |
-
|
21 |
-
|
22 |
-
|
23 |
-
|
24 |
-
)
|
25 |
-
|
26 |
-
|
27 |
-
|
28 |
-
|
29 |
-
download_button.click(
|
30 |
-
fn=download_callback,
|
31 |
-
inputs=None,
|
32 |
-
outputs=download_output
|
33 |
-
)
|
34 |
-
|
35 |
-
with gr.Column():
|
36 |
-
gr.Markdown("### 🤖 Robot Simulator")
|
37 |
-
command_input = gr.Textbox(
|
38 |
-
label="Enter command",
|
39 |
-
placeholder="e.g., say Hello World!",
|
40 |
-
lines=1
|
41 |
-
)
|
42 |
-
send_button = gr.Button("Send Command")
|
43 |
-
response_output = gr.Textbox(label="Robot Response", interactive=False)
|
44 |
-
send_button.click(
|
45 |
-
fn=robot_behavior,
|
46 |
-
inputs=command_input,
|
47 |
-
outputs=response_output
|
48 |
-
)
|
49 |
-
|
50 |
-
return demo
|
51 |
|
52 |
if __name__ == "__main__":
|
53 |
-
|
54 |
-
app.launch()
|
|
|
1 |
+
import os
|
2 |
+
import asyncio
|
3 |
import gradio as gr
|
4 |
+
from deployer.gradio_generator import deploy_callback, robot_behavior
|
5 |
+
|
6 |
+
# Wrapper to run deploy_callback asynchronously
|
7 |
+
async def _deploy_async(idea: str):
|
8 |
+
return deploy_callback(idea)
|
9 |
|
10 |
+
# Synchronous Gradio callback for app generation
|
11 |
+
def generate_app(idea: str):
|
12 |
+
status, zip_path = asyncio.run(_deploy_async(idea))
|
13 |
+
return status, zip_path
|
14 |
+
|
15 |
+
# Build and launch the Gradio interface
|
16 |
+
def main():
|
17 |
+
with gr.Blocks(css=".gradio-container { max-width: 900px; margin: auto; }
|
18 |
+
.section { padding: 1rem; }") as demo:
|
19 |
+
gr.Markdown("# 🚀 RoboSage\nGenerate your custom robot app and test it live.")
|
20 |
|
21 |
with gr.Row():
|
22 |
+
with gr.Column(scale=1):
|
23 |
+
gr.Markdown("## 1️⃣ Generate & Download App")
|
24 |
+
idea_input = gr.Textbox(label="Your Robot Idea", placeholder="e.g. A friendly greeting robot.", lines=2)
|
25 |
+
gen_btn = gr.Button("Generate App")
|
26 |
+
status_out = gr.Textbox(label="Status", interactive=False)
|
27 |
+
zip_out = gr.File(label="Download App ZIP")
|
28 |
+
|
29 |
+
gen_btn.click(fn=generate_app, inputs=[idea_input], outputs=[status_out, zip_out])
|
30 |
+
|
31 |
+
with gr.Column(scale=1):
|
32 |
+
gr.Markdown("## 2️⃣ Robot Simulator")
|
33 |
+
cmd_input = gr.Textbox(label="Command", placeholder="hello or say You rock!", lines=1)
|
34 |
+
sim_btn = gr.Button("Send Command")
|
35 |
+
sim_out = gr.Textbox(label="Robot Response", interactive=False)
|
36 |
+
|
37 |
+
sim_btn.click(fn=robot_behavior, inputs=[cmd_input], outputs=[sim_out])
|
38 |
+
|
39 |
+
demo.launch(server_name="0.0.0.0", server_port=int(os.environ.get("PORT", 7860)), share=False)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
40 |
|
41 |
if __name__ == "__main__":
|
42 |
+
main()
|
|