|
import os |
|
import tempfile |
|
import shutil |
|
import zipfile |
|
|
|
def deploy_callback(idea: str): |
|
""" |
|
Generates a minimal robot app based on the user's idea, packages it |
|
into a ZIP in the system temp directory, and returns a status message |
|
along with the path to the ZIP file. |
|
""" |
|
try: |
|
|
|
title = idea.strip().lower().replace(" ", "_") or "app" |
|
base_dir = os.path.join(tempfile.gettempdir(), f"robosage_{title}") |
|
|
|
|
|
shutil.rmtree(base_dir, ignore_errors=True) |
|
os.makedirs(base_dir, exist_ok=True) |
|
|
|
|
|
main_py = os.path.join(base_dir, "main.py") |
|
with open(main_py, "w") as f: |
|
f.write(f"""def on_command(cmd): |
|
cmd_lower = cmd.strip().lower() |
|
if "hello" in cmd_lower: |
|
return "π€ Hello there!" |
|
else: |
|
return f"π€ I don't understand: '{{cmd}}'" |
|
""") |
|
|
|
|
|
readme = os.path.join(base_dir, "README.md") |
|
with open(readme, "w") as f: |
|
f.write(f"# RoboSage App\nGenerated for idea: {idea}\n\nRun `main.on_command(...)` to simulate.") |
|
|
|
|
|
zip_name = f"robosage_{title}.zip" |
|
zip_path = os.path.join(tempfile.gettempdir(), zip_name) |
|
with zipfile.ZipFile(zip_path, "w", zipfile.ZIP_DEFLATED) as zf: |
|
for root, _, files in os.walk(base_dir): |
|
for fname in files: |
|
fullpath = os.path.join(root, fname) |
|
arcname = os.path.relpath(fullpath, base_dir) |
|
zf.write(fullpath, arcname) |
|
|
|
return f"β
Generated app: {idea}", zip_path |
|
|
|
except Exception as e: |
|
return f"β Error: {e}", None |
|
|
|
|
|
def robot_behavior(cmd: str) -> str: |
|
""" |
|
Simulate a robot response. You can swap this out for your |
|
core_creator or simulator_interface logic if desired. |
|
""" |
|
|
|
lower = cmd.strip().lower() |
|
if "hello" in lower: |
|
return "π€ *waves* Hello there!" |
|
elif lower: |
|
return f"π€ I don't know how to '{cmd}'." |
|
else: |
|
return "β Please say something." |
|
|
|
|
|
|
|
def launch_gradio_app(): |
|
from app import main |
|
main() |
|
|