import os, re, io, zipfile, tempfile, time import gradio as gr from anthropic import Anthropic # -------------------- CONFIG -------------------- MODEL_ID = "claude-sonnet-4-5-20250929" SYSTEM_PROMPT = ( "You are an expert full-stack developer. When the user asks for an app or site, " "return complete production-ready code artifacts in Markdown code fences labeled " "```html```, ```css```, and ```js```. Always include index.html, optionally styles.css and app.js. " "Generate beautiful, functional, responsive designs using pure HTML, CSS, and JS." ) # -------------------- HELPERS -------------------- def parse_artifacts(text: str): files = {} blocks = re.findall(r"```(html|css|js)\s+([\s\S]*?)```", text, re.I) for lang, code in blocks: name = {"html": "index.html", "css": "styles.css", "js": "app.js"}[lang.lower()] if name in files: base, ext = name.split(".") n = 2 while f"{base}{n}.{ext}" in files: n += 1 name = f"{base}{n}.{ext}" files[name] = code.strip() if not files: esc = gr.utils.escape_html(text) files["index.html"] = f"
{esc}"
if "index.html" not in files:
files["index.html"] = "