mgbam commited on
Commit
750f440
Β·
verified Β·
1 Parent(s): 0c77c4b

Update deployer/gradio_generator.py

Browse files
Files changed (1) hide show
  1. deployer/gradio_generator.py +48 -27
deployer/gradio_generator.py CHANGED
@@ -1,65 +1,86 @@
 
 
1
  import gradio as gr
2
  from core_creator.voice_to_app import VoiceToAppCreator
3
  from deployer.simulator_interface import VirtualRobot
4
  from deployer.revenue_tracker import package_artifacts
5
 
6
- def deploy_callback(idea: str):
7
  """
8
- Generates the app based on the provided idea and packages it into a ZIP file.
9
- Returns a status message and the path to the ZIP file.
10
  """
11
  creator = VoiceToAppCreator(idea)
12
  assets = creator.run_pipeline()
13
  title = assets.get("blueprint", {}).get("title", "<unknown>")
14
  zip_path = package_artifacts(assets)
15
- status_msg = f"βœ… Generated app: {title}"
16
- return status_msg, zip_path
 
 
 
 
 
 
 
 
17
 
18
  def robot_behavior(command: str) -> str:
19
  """
20
- Simulates robot action based on a text command.
21
  """
22
  return VirtualRobot().perform_action(command)
23
 
 
24
  def launch_gradio_app():
25
  """
26
- Builds and returns the Gradio Blocks UI for the RoboSage app.
 
 
 
 
27
  """
28
- with gr.Blocks() as demo:
29
- gr.Markdown("# πŸ€– RoboSage: Your Personal Robot App Generator")
 
 
30
 
31
  with gr.Row():
32
  with gr.Column():
33
- gr.Markdown("### πŸ› οΈ Generate Your Robot App")
34
  idea_input = gr.Textbox(
35
- label="Enter your robot idea",
36
- placeholder="e.g., A friendly greeting robot.",
37
  lines=2
38
  )
39
- generate_button = gr.Button("Generate App")
40
- status_output = gr.Textbox(label="Status", interactive=False)
41
- download_output = gr.File(label="Download App ZIP")
42
 
43
- generate_button.click(
44
  fn=deploy_callback,
45
- inputs=idea_input,
46
- outputs=[status_output, download_output]
47
  )
48
 
49
  with gr.Column():
50
- gr.Markdown("### πŸ€– Robot Simulator")
51
- command_input = gr.Textbox(
52
- label="Enter command",
53
- placeholder="e.g., say Hello World!",
54
  lines=1
55
  )
56
- send_button = gr.Button("Send Command")
57
- response_output = gr.Textbox(label="Robot Response", interactive=False)
58
 
59
- send_button.click(
60
  fn=robot_behavior,
61
- inputs=command_input,
62
- outputs=response_output
63
  )
64
 
65
  return demo
 
 
 
 
 
 
1
+ import os
2
+ import asyncio
3
  import gradio as gr
4
  from core_creator.voice_to_app import VoiceToAppCreator
5
  from deployer.simulator_interface import VirtualRobot
6
  from deployer.revenue_tracker import package_artifacts
7
 
8
+ async def _generate_app_async(idea: str):
9
  """
10
+ Run the VoiceToApp pipeline asynchronously and return status + ZIP path.
 
11
  """
12
  creator = VoiceToAppCreator(idea)
13
  assets = creator.run_pipeline()
14
  title = assets.get("blueprint", {}).get("title", "<unknown>")
15
  zip_path = package_artifacts(assets)
16
+ status = f"βœ… Generated app: {title}"
17
+ return status, zip_path
18
+
19
+
20
+ def deploy_callback(idea: str):
21
+ """
22
+ Synchronous wrapper for Gradio: generate and package app.
23
+ """
24
+ return asyncio.run(_generate_app_async(idea))
25
+
26
 
27
  def robot_behavior(command: str) -> str:
28
  """
29
+ Simulate robot action based on a text command.
30
  """
31
  return VirtualRobot().perform_action(command)
32
 
33
+
34
  def launch_gradio_app():
35
  """
36
+ Build and return the Gradio Blocks UI for the RoboSage app.
37
+ """
38
+ css = r"""
39
+ .gradio-container { max-width: 900px; margin: auto; }
40
+ .section { padding: 1rem; }
41
  """
42
+
43
+ demo = gr.Blocks(css=css)
44
+ with demo:
45
+ gr.Markdown("# πŸš€ RoboSage\nGenerate and simulate your custom robot app.")
46
 
47
  with gr.Row():
48
  with gr.Column():
49
+ gr.Markdown("## πŸ› οΈ Generate & Download App")
50
  idea_input = gr.Textbox(
51
+ label="Robot Idea",
52
+ placeholder="e.g. A friendly greeting robot.",
53
  lines=2
54
  )
55
+ gen_btn = gr.Button("Generate App")
56
+ status_out = gr.Textbox(label="Status", interactive=False)
57
+ zip_out = gr.File(label="Download App ZIP")
58
 
59
+ gen_btn.click(
60
  fn=deploy_callback,
61
+ inputs=[idea_input],
62
+ outputs=[status_out, zip_out]
63
  )
64
 
65
  with gr.Column():
66
+ gr.Markdown("## πŸ€– Robot Simulator")
67
+ cmd_input = gr.Textbox(
68
+ label="Command",
69
+ placeholder="hello or say You rock!",
70
  lines=1
71
  )
72
+ sim_btn = gr.Button("Send")
73
+ sim_out = gr.Textbox(label="Robot Response", lines=4, interactive=False)
74
 
75
+ sim_btn.click(
76
  fn=robot_behavior,
77
+ inputs=[cmd_input],
78
+ outputs=[sim_out]
79
  )
80
 
81
  return demo
82
+
83
+
84
+ if __name__ == "__main__":
85
+ demo = launch_gradio_app()
86
+ demo.launch(server_name="0.0.0.0", server_port=int(os.environ.get("PORT", 7860)), share=False)