mgbam commited on
Commit
38e1d70
·
verified ·
1 Parent(s): 38c7720

Update deployer/gradio_generator.py

Browse files
Files changed (1) hide show
  1. deployer/gradio_generator.py +39 -81
deployer/gradio_generator.py CHANGED
@@ -1,89 +1,47 @@
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()
 
 
1
  import os
2
+ import shutil
3
+ import tempfile
4
+ import zipfile
5
+
6
  from core_creator.voice_to_app import VoiceToAppCreator
7
  from deployer.simulator_interface import VirtualRobot
 
8
 
9
+ def deploy_and_package(idea: str):
 
 
 
10
  """
11
+ 1) Runs the VoiceToAppCreator pipeline to generate the app files.
12
+ 2) Packages the generated app directory into a zip under /tmp.
13
+ Returns:
14
+ status_message (str), zip_file_path (str)
 
 
 
 
15
  """
16
+ # 1) Generate assets
17
+ creator = VoiceToAppCreator(idea)
18
+ assets = creator.run_pipeline()
19
+ title = assets.get("blueprint", {}).get("title", "robot_app")
20
+ generated_dir = assets.get("output_dir")
21
+ if not generated_dir or not os.path.isdir(generated_dir):
22
+ return f"❌ Failed to generate app for: {idea}", None
23
+
24
+ # 2) Create a temporary zip under /tmp
25
+ zip_name = f"{title.replace(' ', '_')}.zip"
26
+ zip_path = os.path.join(tempfile.gettempdir(), zip_name)
27
+ # Clean up any old zip
28
+ if os.path.exists(zip_path):
29
+ os.remove(zip_path)
30
+
31
+ # Walk the generated_dir and add to zip
32
+ with zipfile.ZipFile(zip_path, "w", zipfile.ZIP_DEFLATED) as zf:
33
+ for root, _, files in os.walk(generated_dir):
34
+ for fname in files:
35
+ full = os.path.join(root, fname)
36
+ rel = os.path.relpath(full, generated_dir)
37
+ zf.write(full, arcname=rel)
38
+
39
+ status = f"✅ Generated app: **{title}**"
40
+ return status, zip_path
41
+
42
+ def robot_behavior(user_input: str) -> str:
43
  """
44
+ Wraps the VirtualRobot simulator for live commands.
 
 
 
 
 
 
 
 
 
 
 
45
  """
46
+ bot = VirtualRobot()
47
+ return bot.perform_action(user_input)