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

Update deployer/gradio_generator.py

Browse files
Files changed (1) hide show
  1. deployer/gradio_generator.py +32 -32
deployer/gradio_generator.py CHANGED
@@ -1,47 +1,47 @@
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)
 
1
  import os
 
2
  import tempfile
3
  import zipfile
 
4
  from core_creator.voice_to_app import VoiceToAppCreator
5
  from deployer.simulator_interface import VirtualRobot
6
 
7
+ def deploy_callback(idea: str):
8
  """
9
+ 1) Generate the app assets via VoiceToAppCreator
10
+ 2) Package them into a ZIP under /tmp (tempdir)
11
+ Returns (status_message, zip_file_path_or_None)
 
12
  """
13
+ # --- 1) Run pipeline ---
14
+ try:
15
+ creator = VoiceToAppCreator(idea)
16
+ assets = creator.run_pipeline() # should return {"blueprint": {...}, "files": {filename:content_str}}
17
+ title = assets.get("blueprint", {}).get("title", "<unknown>")
18
+ except Exception as e:
19
+ return f"❌ Failed to generate app: {e}", None
20
+
21
+ # --- 2) Package into a ZIP ---
22
+ try:
23
+ # create a fresh temp directory
24
+ base_dir = tempfile.mkdtemp(prefix="robosage_")
25
+ zip_path = os.path.join(base_dir, "app.zip")
26
 
27
+ with zipfile.ZipFile(zip_path, "w", zipfile.ZIP_DEFLATED) as zf:
28
+ for fname, content in assets.get("files", {}).items():
29
+ # ensure subdirs exist
30
+ full_path = os.path.join(base_dir, fname)
31
+ os.makedirs(os.path.dirname(full_path), exist_ok=True)
32
+ # write the generated file
33
+ with open(full_path, "w", encoding="utf-8") as f:
34
+ f.write(content)
35
+ # add to zip under its relative name
36
+ zf.write(full_path, arcname=fname)
37
 
38
+ return f"βœ… Generated app: {title}", zip_path
 
 
 
 
 
 
39
 
40
+ except Exception as e:
41
+ return f"❌ Failed to package app: {e}", None
42
 
43
  def robot_behavior(user_input: str) -> str:
44
  """
45
+ Hook into your simulator.
46
  """
47
+ return VirtualRobot().perform_action(user_input)