Update app.py
Browse files
app.py
CHANGED
|
@@ -1,44 +1,35 @@
|
|
| 1 |
-
# app.py
|
| 2 |
-
|
| 3 |
import os
|
| 4 |
-
import
|
|
|
|
| 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 |
-
|
|
|
|
| 17 |
"""
|
| 18 |
-
status, zip_path =
|
|
|
|
| 19 |
return status, zip_path
|
| 20 |
|
| 21 |
def main():
|
| 22 |
-
"""
|
| 23 |
-
|
| 24 |
-
|
| 25 |
-
|
| 26 |
-
|
| 27 |
-
with gr.Blocks() as demo:
|
| 28 |
-
gr.Markdown("# π RoboSage\nGenerate your custom robot app and test it live.")
|
| 29 |
|
| 30 |
with gr.Row():
|
| 31 |
-
|
| 32 |
-
|
| 33 |
-
gr.Markdown("## 1οΈβ£ Generate & Download App")
|
| 34 |
idea_input = gr.Textbox(
|
| 35 |
label="Your Robot Idea",
|
| 36 |
placeholder="e.g. A friendly greeting robot.",
|
| 37 |
lines=2
|
| 38 |
)
|
| 39 |
-
gen_btn
|
| 40 |
status_out = gr.Textbox(label="Status", interactive=False)
|
| 41 |
-
zip_out
|
| 42 |
|
| 43 |
gen_btn.click(
|
| 44 |
fn=generate_app,
|
|
@@ -46,16 +37,15 @@ def main():
|
|
| 46 |
outputs=[status_out, zip_out]
|
| 47 |
)
|
| 48 |
|
| 49 |
-
|
| 50 |
-
|
| 51 |
-
gr.Markdown("## π€ Robot Simulator")
|
| 52 |
cmd_input = gr.Textbox(
|
| 53 |
label="Command",
|
| 54 |
placeholder="hello or say You rock!",
|
| 55 |
lines=1
|
| 56 |
)
|
| 57 |
sim_btn = gr.Button("Send Command")
|
| 58 |
-
sim_out = gr.Textbox(label="Robot Response",
|
| 59 |
|
| 60 |
sim_btn.click(
|
| 61 |
fn=robot_behavior,
|
|
@@ -63,11 +53,11 @@ def main():
|
|
| 63 |
outputs=[sim_out]
|
| 64 |
)
|
| 65 |
|
| 66 |
-
|
| 67 |
-
|
| 68 |
-
|
| 69 |
-
|
| 70 |
-
|
| 71 |
|
| 72 |
if __name__ == "__main__":
|
| 73 |
main()
|
|
|
|
|
|
|
|
|
|
| 1 |
import os
|
| 2 |
+
import shutil
|
| 3 |
+
from deployer.gradio_generator import deploy_and_package, robot_behavior
|
| 4 |
import gradio as gr
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 5 |
|
| 6 |
def generate_app(idea: str):
|
| 7 |
"""
|
| 8 |
+
Runs the pipeline, packages the app into a zip, and returns
|
| 9 |
+
(status_message, zip_file_path) for Gradio to serve.
|
| 10 |
"""
|
| 11 |
+
status, zip_path = deploy_and_package(idea)
|
| 12 |
+
# Gradio File component needs a Path or file-like
|
| 13 |
return status, zip_path
|
| 14 |
|
| 15 |
def main():
|
| 16 |
+
with gr.Blocks(css="""
|
| 17 |
+
.gradio-container { max-width: 900px; margin: auto; }
|
| 18 |
+
.section { padding: 1rem; }
|
| 19 |
+
""") as demo:
|
| 20 |
+
gr.Markdown("# π RoboSage\nGenerate your custom robot app and download it, then test it live.")
|
|
|
|
|
|
|
| 21 |
|
| 22 |
with gr.Row():
|
| 23 |
+
with gr.Column(elem_id="generate-section"):
|
| 24 |
+
gr.Markdown("## 1οΈβ£ Generate & Download App", elem_classes="section")
|
|
|
|
| 25 |
idea_input = gr.Textbox(
|
| 26 |
label="Your Robot Idea",
|
| 27 |
placeholder="e.g. A friendly greeting robot.",
|
| 28 |
lines=2
|
| 29 |
)
|
| 30 |
+
gen_btn = gr.Button("Generate App & ZIP")
|
| 31 |
status_out = gr.Textbox(label="Status", interactive=False)
|
| 32 |
+
zip_out = gr.File(label="Download App ZIP")
|
| 33 |
|
| 34 |
gen_btn.click(
|
| 35 |
fn=generate_app,
|
|
|
|
| 37 |
outputs=[status_out, zip_out]
|
| 38 |
)
|
| 39 |
|
| 40 |
+
with gr.Column(elem_id="simulate-section"):
|
| 41 |
+
gr.Markdown("## 2οΈβ£ Robot Simulator", elem_classes="section")
|
|
|
|
| 42 |
cmd_input = gr.Textbox(
|
| 43 |
label="Command",
|
| 44 |
placeholder="hello or say You rock!",
|
| 45 |
lines=1
|
| 46 |
)
|
| 47 |
sim_btn = gr.Button("Send Command")
|
| 48 |
+
sim_out = gr.Textbox(label="Robot Response", interactive=False)
|
| 49 |
|
| 50 |
sim_btn.click(
|
| 51 |
fn=robot_behavior,
|
|
|
|
| 53 |
outputs=[sim_out]
|
| 54 |
)
|
| 55 |
|
| 56 |
+
demo.launch(
|
| 57 |
+
server_name="0.0.0.0",
|
| 58 |
+
server_port=int(os.environ.get("PORT", 7860)),
|
| 59 |
+
share=False
|
| 60 |
+
)
|
| 61 |
|
| 62 |
if __name__ == "__main__":
|
| 63 |
main()
|