Update deployer/gradio_generator.py
Browse files- deployer/gradio_generator.py +31 -39
deployer/gradio_generator.py
CHANGED
@@ -1,51 +1,43 @@
|
|
1 |
import os
|
|
|
2 |
import shutil
|
3 |
-
import tempfile
|
4 |
import zipfile
|
5 |
import asyncio
|
|
|
|
|
|
|
6 |
|
7 |
-
|
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 |
-
|
23 |
-
and returns a status message + path to the ZIP.
|
24 |
"""
|
25 |
-
|
26 |
-
|
27 |
-
|
28 |
-
|
29 |
-
|
30 |
-
|
|
|
|
|
|
|
|
|
31 |
|
32 |
-
# Create
|
33 |
-
|
34 |
-
|
35 |
-
|
36 |
-
|
37 |
-
|
38 |
-
|
39 |
-
|
40 |
-
zf.write(abs_path, arcname=rel_path)
|
41 |
|
42 |
-
return f"β
Generated app: {
|
43 |
|
44 |
-
|
45 |
-
return f"β Failed to generate app for: {idea} ({e})", None
|
46 |
-
|
47 |
-
def robot_behavior(user_input: str) -> str:
|
48 |
"""
|
49 |
-
Simulate
|
50 |
"""
|
51 |
-
|
|
|
|
|
|
|
|
1 |
import os
|
2 |
+
import re
|
3 |
import shutil
|
|
|
4 |
import zipfile
|
5 |
import asyncio
|
6 |
+
import tempfile
|
7 |
+
from core_creator.app_blueprint import build_app_code
|
8 |
+
from core_creator.voice_to_app import robot_action
|
9 |
|
10 |
+
async def deploy_callback(idea: str):
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
11 |
"""
|
12 |
+
Generate the app directory, package into zip, return status and path.
|
|
|
13 |
"""
|
14 |
+
# Normalize name
|
15 |
+
safe_name = re.sub(r"[^a-z0-9]+", "_", idea.lower()).strip("_") or "app"
|
16 |
+
with tempfile.TemporaryDirectory() as tmpdir:
|
17 |
+
app_dir = os.path.join(tmpdir, f"robosage_{safe_name}")
|
18 |
+
try:
|
19 |
+
# Build code files
|
20 |
+
os.makedirs(app_dir, exist_ok=False)
|
21 |
+
build_app_code(idea, app_dir)
|
22 |
+
except Exception as e:
|
23 |
+
return f"β Failed to generate app directory for: {idea}", None
|
24 |
|
25 |
+
# Create zip
|
26 |
+
zip_path = os.path.join(tmpdir, f"robosage_{safe_name}.zip")
|
27 |
+
with zipfile.ZipFile(zip_path, "w", zipfile.ZIP_DEFLATED) as zf:
|
28 |
+
for root, _, files in os.walk(app_dir):
|
29 |
+
for file in files:
|
30 |
+
full = os.path.join(root, file)
|
31 |
+
arc = os.path.relpath(full, app_dir)
|
32 |
+
zf.write(full, arc)
|
|
|
33 |
|
34 |
+
return f"β
Generated app: {idea}", zip_path
|
35 |
|
36 |
+
def robot_behavior(command: str):
|
|
|
|
|
|
|
37 |
"""
|
38 |
+
Simulate robot behavior: map command to action.
|
39 |
"""
|
40 |
+
try:
|
41 |
+
return robot_action(command)
|
42 |
+
except Exception:
|
43 |
+
return f"β Unknown action: {command}"
|