mgbam commited on
Commit
7186830
Β·
verified Β·
1 Parent(s): d1faaf8

Update deployer/gradio_generator.py

Browse files
Files changed (1) hide show
  1. deployer/gradio_generator.py +17 -14
deployer/gradio_generator.py CHANGED
@@ -6,39 +6,40 @@ from core_creator.voice_to_app import VoiceToAppCreator
6
  from deployer.simulator_interface import VirtualRobot
7
  from deployer.revenue_tracker import package_artifacts
8
 
9
- # Asynchronous pipeline runner
10
  async def _run_pipeline_async(idea: str) -> str:
11
  creator = VoiceToAppCreator(idea)
12
  assets = creator.run_pipeline()
 
13
  return assets.get("blueprint", {}).get("title", "<unknown>")
14
 
15
- # Synchronous wrapper for Gradio
16
  def generate_app(idea: str) -> str:
17
  title = asyncio.run(_run_pipeline_async(idea))
18
  return f"βœ… Generated app: {title}"
19
 
20
- # Package the last-generated artifacts into a ZIP and return its path
21
  def get_app_zip() -> str:
22
  zip_path = package_artifacts()
23
  if not os.path.isfile(zip_path):
24
- raise FileNotFoundError(f"ZIP not found at {zip_path}")
25
  return zip_path
26
 
27
- # Simulated robot behavior endpoint
28
  def robot_behavior(command: str) -> str:
29
  return VirtualRobot().perform_action(command)
30
 
31
- # Build and launch the Gradio interface
32
  def launch_gradio_app():
33
  css = r"""
34
  .gradio-container { max-width: 800px; margin: auto; }
35
- .section { margin-bottom: 2em; }
36
  """
37
 
38
  with gr.Blocks(css=css) as demo:
39
- gr.Markdown("# πŸš€ RoboSage\nGenerate your custom robot app and test it live.")
 
40
 
41
- with gr.Box(elem_id="generate-app", variant="panel"):
 
42
  gr.Markdown("## 1️⃣ Generate App")
43
  idea_input = gr.Textbox(label="Your Robot Idea", placeholder="e.g. A friendly greeting robot", lines=1)
44
  gen_btn = gr.Button("Generate App")
@@ -46,14 +47,16 @@ def launch_gradio_app():
46
 
47
  gen_btn.click(fn=generate_app, inputs=[idea_input], outputs=[status_out])
48
 
49
- with gr.Box(elem_id="download-app", variant="panel"):
 
50
  gr.Markdown("## πŸ“¦ Download Packaged App")
51
  dl_btn = gr.Button("Download App ZIP")
52
  dl_file = gr.File(label="App ZIP File")
53
 
54
  dl_btn.click(fn=get_app_zip, inputs=None, outputs=[dl_file])
55
 
56
- with gr.Box(elem_id="robot-sim", variant="panel"):
 
57
  gr.Markdown("## 2️⃣ Robot Simulator")
58
  cmd_input = gr.Textbox(label="Command", placeholder="hello or say You rock!", lines=1)
59
  sim_btn = gr.Button("Send")
@@ -69,6 +72,6 @@ def launch_gradio_app():
69
 
70
  return demo
71
 
72
- # Expose for import
73
- robot_behavior = robot_behavior
74
- launch_gradio_app = launch_gradio_app
 
6
  from deployer.simulator_interface import VirtualRobot
7
  from deployer.revenue_tracker import package_artifacts
8
 
9
+ # --- Async pipeline runner ---
10
  async def _run_pipeline_async(idea: str) -> str:
11
  creator = VoiceToAppCreator(idea)
12
  assets = creator.run_pipeline()
13
+ # blueprint title fallback
14
  return assets.get("blueprint", {}).get("title", "<unknown>")
15
 
16
+ # --- Sync wrappers for Gradio ---
17
  def generate_app(idea: str) -> str:
18
  title = asyncio.run(_run_pipeline_async(idea))
19
  return f"βœ… Generated app: {title}"
20
 
 
21
  def get_app_zip() -> str:
22
  zip_path = package_artifacts()
23
  if not os.path.isfile(zip_path):
24
+ raise FileNotFoundError(f"Could not find ZIP at {zip_path}")
25
  return zip_path
26
 
 
27
  def robot_behavior(command: str) -> str:
28
  return VirtualRobot().perform_action(command)
29
 
30
+ # --- Build & launch Gradio UI ---
31
  def launch_gradio_app():
32
  css = r"""
33
  .gradio-container { max-width: 800px; margin: auto; }
34
+ .gradio-box { padding: 1em; margin-bottom: 2em; border: 1px solid #e2e2e2; border-radius: 8px; }
35
  """
36
 
37
  with gr.Blocks(css=css) as demo:
38
+ gr.Markdown("# πŸš€ RoboSage")
39
+ gr.Markdown("Generate your custom robot app and test it live.")
40
 
41
+ # Generate App section
42
+ with gr.Box(elem_id="generate-app", css_class="gradio-box"):
43
  gr.Markdown("## 1️⃣ Generate App")
44
  idea_input = gr.Textbox(label="Your Robot Idea", placeholder="e.g. A friendly greeting robot", lines=1)
45
  gen_btn = gr.Button("Generate App")
 
47
 
48
  gen_btn.click(fn=generate_app, inputs=[idea_input], outputs=[status_out])
49
 
50
+ # Download ZIP section
51
+ with gr.Box(elem_id="download-app", css_class="gradio-box"):
52
  gr.Markdown("## πŸ“¦ Download Packaged App")
53
  dl_btn = gr.Button("Download App ZIP")
54
  dl_file = gr.File(label="App ZIP File")
55
 
56
  dl_btn.click(fn=get_app_zip, inputs=None, outputs=[dl_file])
57
 
58
+ # Simulator section
59
+ with gr.Box(elem_id="robot-sim", css_class="gradio-box"):
60
  gr.Markdown("## 2️⃣ Robot Simulator")
61
  cmd_input = gr.Textbox(label="Command", placeholder="hello or say You rock!", lines=1)
62
  sim_btn = gr.Button("Send")
 
72
 
73
  return demo
74
 
75
+ # Expose for external import
76
+ robot_behavior = robot_behavior
77
+ launch_gradio_app = launch_gradio_app