mgbam commited on
Commit
4e2e4a9
Β·
verified Β·
1 Parent(s): 2e90048

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +44 -15
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
- with gr.Blocks(css=".gradio-container { max-width: 900px; margin: auto; }
19
- .section { padding: 1rem; }") as demo:
 
 
 
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(label="Your Robot Idea", placeholder="e.g. A friendly greeting robot.", lines=2)
26
- gen_btn = gr.Button("Generate App")
 
 
 
 
27
  status_out = gr.Textbox(label="Status", interactive=False)
28
- zip_out = gr.File(label="Download App ZIP")
29
 
30
- gen_btn.click(fn=generate_app, inputs=[idea_input], outputs=[status_out, zip_out])
 
 
 
 
31
 
 
32
  with gr.Column(scale=1):
33
- gr.Markdown("## 2️⃣ Robot Simulator")
34
- cmd_input = gr.Textbox(label="Command", placeholder="hello or say You rock!", lines=1)
 
 
 
 
35
  sim_btn = gr.Button("Send Command")
36
- sim_out = gr.Textbox(label="Robot Response", interactive=False)
37
 
38
- sim_btn.click(fn=robot_behavior, inputs=[cmd_input], outputs=[sim_out])
 
 
 
 
39
 
40
- demo.launch(server_name="0.0.0.0", server_port=int(os.environ.get("PORT", 7860)), share=False)
 
 
 
 
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()