mgbam commited on
Commit
f69fdac
Β·
verified Β·
1 Parent(s): bb15a41

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +49 -72
app.py CHANGED
@@ -1,77 +1,54 @@
1
  # app.py
2
- # Unified RoboSage Deployer & Simulator (CPU & Spaces-compatible)
3
 
4
- import asyncio
5
  import gradio as gr
6
- from deployer.gradio_generator import robot_behavior, launch_gradio_app
7
-
8
- async def run_pipeline(idea: str) -> tuple[str, str]:
9
- """
10
- Runs the voice-to-app pipeline and returns a tuple of
11
- (path_to_zip, app_title).
12
- """
13
- # launch_gradio_app should now generate the app, package it into a ZIP,
14
- # and return (zip_path, title)
15
- zip_path, title = await asyncio.to_thread(launch_gradio_app, idea)
16
- return zip_path, title
17
-
18
- def deploy_callback(idea: str):
19
- """
20
- Synchronous wrapper for Gradio that returns
21
- (status_message, zip_file_path) for downloading.
22
- """
23
- zip_path, title = asyncio.run(run_pipeline(idea))
24
- status = f"βœ… Generated app: {title}"
25
- return status, zip_path
26
-
27
- def simulator_callback(cmd: str) -> str:
28
- """
29
- Simulate robot action based on user text.
30
- """
31
- return robot_behavior(cmd)
32
-
33
- # Build the unified Gradio interface
34
- with gr.Blocks(css="""
35
- .gradio-container { max-width: 900px; margin: auto; }
36
- .section { padding: 1rem; }
37
- """) as demo:
38
-
39
- gr.Markdown("# πŸš€ RoboSage\nGenerate your custom robot app and test it live.")
40
-
41
- with gr.Row():
42
- with gr.Column(scale=1):
43
- gr.Markdown("## 1️⃣ Generate App", elem_classes="section")
44
- user_idea = gr.Textbox(
45
- label="Your Robot Idea",
46
- placeholder="e.g. A friendly greeting robot.",
47
- lines=1
48
- )
49
- deploy_btn = gr.Button("Generate App")
50
- deploy_status = gr.Textbox(label="Status", interactive=False)
51
- download_zip = gr.File(label="Download App ZIP")
52
-
53
- deploy_btn.click(
54
- fn=deploy_callback,
55
- inputs=[user_idea],
56
- outputs=[deploy_status, download_zip]
57
- )
58
-
59
- with gr.Column(scale=1):
60
- gr.Markdown("## 2️⃣ Robot Simulator", elem_classes="section")
61
- robot_input = gr.Textbox(
62
- label="Speak or Type Command",
63
- placeholder="hello or say You rock!",
64
- lines=1
65
- )
66
- robot_btn = gr.Button("Send")
67
- robot_output = gr.Textbox(label="Robot Response", lines=4, interactive=False)
68
-
69
- robot_btn.click(
70
- fn=simulator_callback,
71
- inputs=[robot_input],
72
- outputs=[robot_output]
73
- )
74
 
75
  if __name__ == "__main__":
76
- # Launch: set share=True if you want a public HF Spaces link, otherwise omit.
77
- demo.launch()
 
1
  # app.py
 
2
 
 
3
  import gradio as gr
4
+ from deployer.gradio_generator import deploy_callback, robot_behavior, download_callback
5
+
6
+ def launch_gradio_app():
7
+ with gr.Blocks() as demo:
8
+ gr.Markdown("# πŸ€– RoboSage: Your Personal Robot App Generator")
9
+
10
+ with gr.Row():
11
+ with gr.Column():
12
+ gr.Markdown("### πŸ› οΈ Generate Your Robot App")
13
+ idea_input = gr.Textbox(
14
+ label="Enter your robot idea",
15
+ placeholder="e.g., A friendly greeting robot.",
16
+ lines=2
17
+ )
18
+ generate_button = gr.Button("Generate App")
19
+ status_output = gr.Textbox(label="Status", interactive=False)
20
+ generate_button.click(
21
+ fn=deploy_callback,
22
+ inputs=idea_input,
23
+ outputs=status_output
24
+ )
25
+
26
+ gr.Markdown("### πŸ“¦ Download Your App")
27
+ download_button = gr.Button("Download App ZIP")
28
+ download_output = gr.File(label="Download ZIP")
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
+ app = launch_gradio_app()
54
+ app.launch()