Update deployer/gradio_generator.py
Browse files- 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
|
10 |
"""
|
11 |
-
1)
|
12 |
-
2)
|
13 |
-
Returns
|
14 |
-
status_message (str), zip_file_path (str)
|
15 |
"""
|
16 |
-
# 1)
|
17 |
-
|
18 |
-
|
19 |
-
|
20 |
-
|
21 |
-
|
22 |
-
return f"β Failed to generate app
|
|
|
|
|
|
|
|
|
|
|
|
|
23 |
|
24 |
-
|
25 |
-
|
26 |
-
|
27 |
-
|
28 |
-
|
29 |
-
|
|
|
|
|
|
|
|
|
30 |
|
31 |
-
|
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 |
-
|
40 |
-
|
41 |
|
42 |
def robot_behavior(user_input: str) -> str:
|
43 |
"""
|
44 |
-
|
45 |
"""
|
46 |
-
|
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)
|
|