mgbam commited on
Commit
7857548
Β·
verified Β·
1 Parent(s): ff11f84

Update deployer/gradio_generator.py

Browse files
Files changed (1) hide show
  1. 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
- 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)
 
 
 
 
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}"