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

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +46 -28
app.py CHANGED
@@ -1,59 +1,77 @@
1
- # app.py - Unified RoboSage Deployer & Simulator (CPU & Spaces-compatible)
 
2
 
3
  import asyncio
4
  import gradio as gr
5
- from core_creator.voice_to_app import VoiceToAppCreator
6
  from deployer.gradio_generator import robot_behavior, launch_gradio_app
7
 
8
- async def run_pipeline(idea: str) -> str:
9
  """
10
- Runs voice-to-app pipeline and returns a status message.
 
11
  """
12
- creator = VoiceToAppCreator(idea)
13
- assets = creator.run_pipeline()
14
- title = assets.get("blueprint", {}).get("title", "<unknown>")
15
- return f"✅ Generated app: {title}"
16
 
17
- # Synchronous wrapper for Gradio
 
 
 
 
 
 
 
18
 
19
- def deploy_callback(idea: str) -> str:
20
- return asyncio.run(run_pipeline(idea))
 
 
 
21
 
22
- # Build unified Gradio interface
23
- with gr.Blocks() as demo:
24
- gr.Markdown("""
25
- # 🚀 RoboSage
26
- Generate your custom robot app and test it live.
27
- """)
 
28
 
29
  with gr.Row():
30
- with gr.Column():
31
- gr.Markdown("## 1️⃣ Generate App")
32
  user_idea = gr.Textbox(
33
  label="Your Robot Idea",
34
- placeholder="e.g. A friendly greeting robot."
 
35
  )
36
- deploy_btn = gr.Button("Generate App", key="deploy-app-btn")
37
  deploy_status = gr.Textbox(label="Status", interactive=False)
 
 
38
  deploy_btn.click(
39
  fn=deploy_callback,
40
  inputs=[user_idea],
41
- outputs=[deploy_status]
42
  )
43
 
44
- with gr.Column():
45
- gr.Markdown("## 2️⃣ Robot Simulator")
46
  robot_input = gr.Textbox(
47
- label="Command",
48
- placeholder="hello or say You rock!"
 
49
  )
50
- robot_btn = gr.Button("Send", key="simulate-btn")
51
  robot_output = gr.Textbox(label="Robot Response", lines=4, interactive=False)
 
52
  robot_btn.click(
53
- fn=robot_behavior,
54
  inputs=[robot_input],
55
  outputs=[robot_output]
56
  )
57
 
58
  if __name__ == "__main__":
 
59
  demo.launch()
 
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()