Update deployer/gradio_generator.py
Browse files- deployer/gradio_generator.py +36 -56
deployer/gradio_generator.py
CHANGED
@@ -1,71 +1,51 @@
|
|
1 |
import os
|
2 |
-
import tempfile
|
3 |
import shutil
|
|
|
4 |
import zipfile
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
5 |
|
6 |
def deploy_callback(idea: str):
|
7 |
"""
|
8 |
-
|
9 |
-
|
10 |
-
along with the path to the ZIP file.
|
11 |
"""
|
12 |
try:
|
13 |
-
|
14 |
-
title =
|
15 |
-
|
16 |
-
|
17 |
-
|
18 |
-
|
19 |
-
|
20 |
-
|
21 |
-
|
22 |
-
|
23 |
-
|
24 |
-
f.write(f"""def on_command(cmd):
|
25 |
-
cmd_lower = cmd.strip().lower()
|
26 |
-
if "hello" in cmd_lower:
|
27 |
-
return "π€ Hello there!"
|
28 |
-
else:
|
29 |
-
return f"π€ I don't understand: '{{cmd}}'"
|
30 |
-
""")
|
31 |
-
|
32 |
-
# 2) Create a README
|
33 |
-
readme = os.path.join(base_dir, "README.md")
|
34 |
-
with open(readme, "w") as f:
|
35 |
-
f.write(f"# RoboSage App\nGenerated for idea: {idea}\n\nRun `main.on_command(...)` to simulate.")
|
36 |
-
|
37 |
-
# 3) Zip the directory
|
38 |
-
zip_name = f"robosage_{title}.zip"
|
39 |
-
zip_path = os.path.join(tempfile.gettempdir(), zip_name)
|
40 |
-
with zipfile.ZipFile(zip_path, "w", zipfile.ZIP_DEFLATED) as zf:
|
41 |
-
for root, _, files in os.walk(base_dir):
|
42 |
for fname in files:
|
43 |
-
|
44 |
-
|
45 |
-
zf.write(
|
46 |
|
47 |
-
return f"β
Generated app: {
|
48 |
|
49 |
except Exception as e:
|
50 |
-
return f"β
|
51 |
|
52 |
-
|
53 |
-
def robot_behavior(cmd: str) -> str:
|
54 |
"""
|
55 |
-
Simulate
|
56 |
-
core_creator or simulator_interface logic if desired.
|
57 |
"""
|
58 |
-
|
59 |
-
lower = cmd.strip().lower()
|
60 |
-
if "hello" in lower:
|
61 |
-
return "π€ *waves* Hello there!"
|
62 |
-
elif lower:
|
63 |
-
return f"π€ I don't know how to '{cmd}'."
|
64 |
-
else:
|
65 |
-
return "β Please say something."
|
66 |
-
|
67 |
-
|
68 |
-
# Optional entrypoint if you want to import a launcher function
|
69 |
-
def launch_gradio_app():
|
70 |
-
from app import main
|
71 |
-
main()
|
|
|
1 |
import os
|
|
|
2 |
import shutil
|
3 |
+
import tempfile
|
4 |
import zipfile
|
5 |
+
import asyncio
|
6 |
+
|
7 |
+
from core_creator.voice_to_app import VoiceToAppCreator
|
8 |
+
from deployer.simulator_interface import VirtualRobot
|
9 |
+
|
10 |
+
def run_pipeline(idea: str) -> dict:
|
11 |
+
"""
|
12 |
+
Synchronous wrapper to run the voice-to-app pipeline and return
|
13 |
+
the assets dict, which must include a 'blueprint' with a 'title',
|
14 |
+
and the path to the generated project directory.
|
15 |
+
"""
|
16 |
+
creator = VoiceToAppCreator(idea)
|
17 |
+
assets = creator.run_pipeline()
|
18 |
+
return assets
|
19 |
|
20 |
def deploy_callback(idea: str):
|
21 |
"""
|
22 |
+
Called by Gradio. Runs pipeline, packages into a ZIP,
|
23 |
+
and returns a status message + path to the ZIP.
|
|
|
24 |
"""
|
25 |
try:
|
26 |
+
assets = run_pipeline(idea)
|
27 |
+
title = assets.get("blueprint", {}).get("title", None) or "unknown"
|
28 |
+
gen_dir = assets.get("project_dir", None)
|
29 |
+
if not gen_dir or not os.path.isdir(gen_dir):
|
30 |
+
return f"β No generated directory found for: {idea}", None
|
31 |
+
|
32 |
+
# Create ZIP in temporary file
|
33 |
+
tmp_fd, tmp_path = tempfile.mkstemp(suffix=".zip")
|
34 |
+
os.close(tmp_fd)
|
35 |
+
with zipfile.ZipFile(tmp_path, "w", zipfile.ZIP_DEFLATED) as zf:
|
36 |
+
for root, _, files in os.walk(gen_dir):
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
37 |
for fname in files:
|
38 |
+
abs_path = os.path.join(root, fname)
|
39 |
+
rel_path = os.path.relpath(abs_path, gen_dir)
|
40 |
+
zf.write(abs_path, arcname=rel_path)
|
41 |
|
42 |
+
return f"β
Generated app: {title}", tmp_path
|
43 |
|
44 |
except Exception as e:
|
45 |
+
return f"β Failed to generate app for: {idea} ({e})", None
|
46 |
|
47 |
+
def robot_behavior(user_input: str) -> str:
|
|
|
48 |
"""
|
49 |
+
Simulate the robot action via VirtualRobot.
|
|
|
50 |
"""
|
51 |
+
return VirtualRobot().perform_action(user_input)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|