Update app.py
Browse files
app.py
CHANGED
@@ -1,43 +1,72 @@
|
|
|
|
|
|
1 |
import os
|
2 |
import asyncio
|
3 |
import gradio as gr
|
4 |
from deployer.gradio_generator import deploy_callback, robot_behavior
|
5 |
-
from deployer.gradio_generator import launch_gradio_app
|
6 |
|
7 |
-
# Wrapper to run deploy_callback asynchronously
|
8 |
async def _deploy_async(idea: str):
|
|
|
|
|
|
|
9 |
return deploy_callback(idea)
|
10 |
|
11 |
-
# Synchronous Gradio callback for app generation
|
12 |
def generate_app(idea: str):
|
|
|
|
|
|
|
13 |
status, zip_path = asyncio.run(_deploy_async(idea))
|
14 |
return status, zip_path
|
15 |
|
16 |
-
# Build and launch the Gradio interface
|
17 |
def main():
|
18 |
-
|
19 |
-
|
|
|
|
|
|
|
20 |
gr.Markdown("# π RoboSage\nGenerate your custom robot app and test it live.")
|
21 |
|
22 |
with gr.Row():
|
|
|
23 |
with gr.Column(scale=1):
|
24 |
gr.Markdown("## 1οΈβ£ Generate & Download App")
|
25 |
-
idea_input = gr.Textbox(
|
26 |
-
|
|
|
|
|
|
|
|
|
27 |
status_out = gr.Textbox(label="Status", interactive=False)
|
28 |
-
zip_out
|
29 |
|
30 |
-
gen_btn.click(
|
|
|
|
|
|
|
|
|
31 |
|
|
|
32 |
with gr.Column(scale=1):
|
33 |
-
gr.Markdown("##
|
34 |
-
cmd_input = gr.Textbox(
|
|
|
|
|
|
|
|
|
35 |
sim_btn = gr.Button("Send Command")
|
36 |
-
sim_out = gr.Textbox(label="Robot Response", interactive=False)
|
37 |
|
38 |
-
sim_btn.click(
|
|
|
|
|
|
|
|
|
39 |
|
40 |
-
demo.launch(
|
|
|
|
|
|
|
|
|
41 |
|
42 |
if __name__ == "__main__":
|
43 |
main()
|
|
|
1 |
+
# app.py
|
2 |
+
|
3 |
import os
|
4 |
import asyncio
|
5 |
import gradio as gr
|
6 |
from deployer.gradio_generator import deploy_callback, robot_behavior
|
|
|
7 |
|
|
|
8 |
async def _deploy_async(idea: str):
|
9 |
+
"""
|
10 |
+
Helper to call deploy_callback in an async context.
|
11 |
+
"""
|
12 |
return deploy_callback(idea)
|
13 |
|
|
|
14 |
def generate_app(idea: str):
|
15 |
+
"""
|
16 |
+
Synchronous Gradio callback for app generation + ZIP download.
|
17 |
+
"""
|
18 |
status, zip_path = asyncio.run(_deploy_async(idea))
|
19 |
return status, zip_path
|
20 |
|
|
|
21 |
def main():
|
22 |
+
"""
|
23 |
+
Build and launch the Gradio interface.
|
24 |
+
"""
|
25 |
+
# No inline CSS hereβstyling lives in deployer/gradio_generator.py
|
26 |
+
with gr.Blocks() as demo:
|
27 |
gr.Markdown("# π RoboSage\nGenerate your custom robot app and test it live.")
|
28 |
|
29 |
with gr.Row():
|
30 |
+
# βββββββββ Generate & Download App βββββββββ
|
31 |
with gr.Column(scale=1):
|
32 |
gr.Markdown("## 1οΈβ£ Generate & Download App")
|
33 |
+
idea_input = gr.Textbox(
|
34 |
+
label="Your Robot Idea",
|
35 |
+
placeholder="e.g. A friendly greeting robot.",
|
36 |
+
lines=2
|
37 |
+
)
|
38 |
+
gen_btn = gr.Button("Generate App")
|
39 |
status_out = gr.Textbox(label="Status", interactive=False)
|
40 |
+
zip_out = gr.File(label="Download App ZIP")
|
41 |
|
42 |
+
gen_btn.click(
|
43 |
+
fn=generate_app,
|
44 |
+
inputs=[idea_input],
|
45 |
+
outputs=[status_out, zip_out]
|
46 |
+
)
|
47 |
|
48 |
+
# βββββββββ Robot Simulator βββββββββ
|
49 |
with gr.Column(scale=1):
|
50 |
+
gr.Markdown("## π€ Robot Simulator")
|
51 |
+
cmd_input = gr.Textbox(
|
52 |
+
label="Command",
|
53 |
+
placeholder="hello or say You rock!",
|
54 |
+
lines=1
|
55 |
+
)
|
56 |
sim_btn = gr.Button("Send Command")
|
57 |
+
sim_out = gr.Textbox(label="Robot Response", lines=4, interactive=False)
|
58 |
|
59 |
+
sim_btn.click(
|
60 |
+
fn=robot_behavior,
|
61 |
+
inputs=[cmd_input],
|
62 |
+
outputs=[sim_out]
|
63 |
+
)
|
64 |
|
65 |
+
demo.launch(
|
66 |
+
server_name="0.0.0.0",
|
67 |
+
server_port=int(os.environ.get("PORT", 7860)),
|
68 |
+
share=False
|
69 |
+
)
|
70 |
|
71 |
if __name__ == "__main__":
|
72 |
main()
|