mgbam commited on
Commit
9730a79
Β·
verified Β·
1 Parent(s): b4299eb

Update deployer/gradio_generator.py

Browse files
Files changed (1) hide show
  1. deployer/gradio_generator.py +65 -48
deployer/gradio_generator.py CHANGED
@@ -1,72 +1,89 @@
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
- Generate the app from the user idea, package artifacts into a ZIP,
9
- and return a (status_message, zip_path) tuple.
10
  """
11
- # 1. Run the core pipeline
12
- creator = VoiceToAppCreator(idea)
13
- assets = creator.run_pipeline()
14
-
15
- # 2. Extract a title for status display
16
  title = assets.get("blueprint", {}).get("title", "<unknown>")
17
-
18
- # 3. Package everything into app_package.zip
19
  zip_path = package_artifacts(assets)
20
-
21
- # 4. Return status message and ZIP filepath
22
- status = f"βœ… Generated app: {title}"
23
- return status, zip_path
24
 
25
  def robot_behavior(command: str) -> str:
26
  """
27
- Simulate robot action based on a text command.
28
  """
29
  return VirtualRobot().perform_action(command)
30
 
31
- def launch_gradio_app():
32
- """
33
- Build and return the Gradio Blocks UI:
34
- - Left column: generate & download
35
- - Right column: robot simulator
 
 
 
 
 
36
  """
37
- demo = gr.Blocks()
38
 
39
- with demo:
40
  gr.Markdown("# πŸš€ RoboSage\nGenerate your custom robot app and test it live.")
41
 
42
  with gr.Row():
43
- # β€” Generate & Download App β€”
44
- with gr.Column():
45
- gr.Markdown("## 1️⃣ Generate & Download App")
46
- idea_in = gr.Textbox(label="Your Robot Idea",
47
- placeholder="e.g. A friendly greeting robot.",
48
- lines=2)
49
- gen_btn = gr.Button("Generate App")
50
- status_out= gr.Textbox(label="Status", interactive=False)
51
- zip_out = gr.File(label="Download App ZIP")
52
-
53
- # Wire up generation β†’ status + ZIP
54
- gen_btn.click(fn=deploy_callback,
55
- inputs=[idea_in],
56
- outputs=[status_out, zip_out])
 
 
 
 
 
 
 
57
 
58
- # β€” Robot Simulator β€”
59
- with gr.Column():
60
- gr.Markdown("## πŸ€– Robot Simulator")
61
- cmd_in = gr.Textbox(label="Command",
62
- placeholder="hello or say You rock!",
63
- lines=1)
 
 
64
  sim_btn = gr.Button("Send Command")
65
- sim_out = gr.Textbox(label="Robot Response", lines=4, interactive=False)
 
 
 
 
 
 
 
 
66
 
67
- # Wire up simulator
68
- sim_btn.click(fn=robot_behavior,
69
- inputs=[cmd_in],
70
- outputs=[sim_out])
 
71
 
72
- return demo
 
 
1
+ # File: deployer/gradio_generator.py
2
+ import os
3
  from core_creator.voice_to_app import VoiceToAppCreator
4
  from deployer.simulator_interface import VirtualRobot
5
  from deployer.revenue_tracker import package_artifacts
6
 
7
  def deploy_callback(idea: str):
8
  """
9
+ Generate the robot app from the user's idea and package it as a ZIP.
10
+ Returns a status message and the path to the ZIP file for download.
11
  """
12
+ # Create app artifacts
13
+ assets = VoiceToAppCreator(idea).run_pipeline()
 
 
 
14
  title = assets.get("blueprint", {}).get("title", "<unknown>")
15
+ # Package into a ZIP and return
 
16
  zip_path = package_artifacts(assets)
17
+ return f"βœ… Generated app: {title}", zip_path
 
 
 
18
 
19
  def robot_behavior(command: str) -> str:
20
  """
21
+ Simulate robot action based on text command.
22
  """
23
  return VirtualRobot().perform_action(command)
24
 
25
+
26
+ # File: app.py
27
+ import os
28
+ import gradio as gr
29
+ from deployer.gradio_generator import deploy_callback, robot_behavior
30
+
31
+ def main():
32
+ css = """
33
+ .gradio-container { max-width: 900px; margin: auto; }
34
+ .section { padding: 1rem; }
35
  """
 
36
 
37
+ with gr.Blocks(css=css) as demo:
38
  gr.Markdown("# πŸš€ RoboSage\nGenerate your custom robot app and test it live.")
39
 
40
  with gr.Row():
41
+ # Section 1: App Generation & Download
42
+ with gr.Column(scale=1):
43
+ gr.Markdown("## 1️⃣ Generate & Download App", elem_classes="section")
44
+ idea_input = gr.Textbox(
45
+ label="Your Robot Idea",
46
+ placeholder="e.g. A friendly greeting robot.",
47
+ lines=2
48
+ )
49
+ gen_btn = gr.Button("Generate App")
50
+ status_out = gr.Textbox(
51
+ label="Status",
52
+ interactive=False
53
+ )
54
+ zip_out = gr.File(
55
+ label="Download App ZIP"
56
+ )
57
+ gen_btn.click(
58
+ fn=deploy_callback,
59
+ inputs=[idea_input],
60
+ outputs=[status_out, zip_out]
61
+ )
62
 
63
+ # Section 2: Robot Simulator
64
+ with gr.Column(scale=1):
65
+ gr.Markdown("## 2️⃣ Robot Simulator", elem_classes="section")
66
+ cmd_input = gr.Textbox(
67
+ label="Command",
68
+ placeholder="hello or say You rock!",
69
+ lines=1
70
+ )
71
  sim_btn = gr.Button("Send Command")
72
+ sim_out = gr.Textbox(
73
+ label="Robot Response",
74
+ interactive=False
75
+ )
76
+ sim_btn.click(
77
+ fn=robot_behavior,
78
+ inputs=[cmd_input],
79
+ outputs=[sim_out]
80
+ )
81
 
82
+ demo.launch(
83
+ server_name="0.0.0.0",
84
+ server_port=int(os.getenv("PORT", 7860)),
85
+ share=False
86
+ )
87
 
88
+ if __name__ == "__main__":
89
+ main()