import gradio as gr from pathlib import Path import sys # Paths PROJECT_ROOT = Path(__file__).resolve().parent GENERATED_SCRIPT_PATH = PROJECT_ROOT / "generated" / "result_script.py" # Add root to sys.path so we can import process.py from app/ sys.path.insert(0, str(PROJECT_ROOT / "app")) from app.process import main as generate_from_llm # This runs generation def generate_script_and_preview(description): """ Generates the FreeCAD script using process.py logic and returns: - The script text for preview - The file path for download """ import builtins original_input = builtins.input builtins.input = lambda _: description try: generate_from_llm() finally: builtins.input = original_input if GENERATED_SCRIPT_PATH.exists(): script_text = GENERATED_SCRIPT_PATH.read_text(encoding="utf-8") return script_text, str(GENERATED_SCRIPT_PATH) else: return "Error: Script was not generated.", None css = """ body { background-color: #202020; color: white; margin: 0; padding: 0; } .gradio-container { max-width: 1400px; width: 95vw; margin: auto; } .title { text-align: center; font-size: 2.5em; margin-bottom: 0.1em; } .description { text-align: center; font-size: 1.1em; margin-bottom: 1em; color: #ccc; } .preview-box { max-height: 400px; background-color: #111; border: 1px solid #444; padding: 10px; font-family: monospace; white-space: pre-wrap; color: #0f0; } .download-container { display: flex; flex-direction: column; align-items: flex-start; gap: 0.5em; padding-left: 15px; height: 400px; justify-content: flex-start; width: 500px; } .download-button { width: 100%; } .instructions { font-size: 0.9em; color: #aaa; max-width: 300px; white-space: pre-line; } .footer { margin-top: 2em; text-align: center; font-size: 0.9em; color: #888; border-top: 1px solid #444; padding-top: 1em; } .footer a { color: #6af; text-decoration: none; } .footer a:hover { text-decoration: underline; } """ # Description # ToDo write as features cadomatic_description_md = """