Spaces:
Sleeping
Sleeping
fixes
Browse filesFiles changed (2)
- backend_parsers.py+60-5
- backend_prompts.py+28-8
14 unmodified lines151617181920212223242514 unmodified linesUses comprehensive parsing patterns to handle various LLM output formats.Updated to use transformers.js v3.8.0 CDN."""files = {'index.html': '','index.js': '','style.css': ''}# Multiple patterns to match the three code blocks with different variationshtml_patterns = [14 unmodified lines15161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798014 unmodified linesUses comprehensive parsing patterns to handle various LLM output formats.Updated to use transformers.js v3.8.0 CDN."""# Check if code starts with HTML instead of markers (common LLM mistake)if code.strip().startswith('<!DOCTYPE') or code.strip().startswith('<html'):print("[Parser] WARNING: Code starts with HTML instead of === index.html === marker")print("[Parser] Attempting to extract files from malformed output...")# Try to split by === markers that do existif '=== index.js ===' in code and '=== style.css ===' in code:# Extract HTML as everything before === index.js ===html_end = code.find('=== index.js ===')html_content = code[:html_end].strip()# Extract JS between === index.js === and === style.css ===js_start = code.find('=== index.js ===') + len('=== index.js ===')js_end = code.find('=== style.css ===')js_content = code[js_start:js_end].strip()# Extract CSS after === style.css ===css_start = code.find('=== style.css ===') + len('=== style.css ===')css_content = code[css_start:].strip()print(f"[Parser] Recovered HTML: {len(html_content)} chars")print(f"[Parser] Recovered JS: {len(js_content)} chars")print(f"[Parser] Recovered CSS: {len(css_content)} chars")files = {'index.html': html_content,'index.js': js_content,'style.css': css_content}# Normalize imports and return early since we've already parsed everythingcdn_url = "https://cdn.jsdelivr.net/npm/@huggingface/transformers@3.8.0"for file_key in ['index.html', 'index.js']:if files[file_key]:content = files[file_key]content = re.sub(r"from\s+['\"]https://cdn.jsdelivr.net/npm/@huggingface/transformers@[^'\"]+['\"]",f"from '{cdn_url}'",content)content = re.sub(r"from\s+['\"]https://cdn.jsdelivr.net/npm/@xenova/transformers@[^'\"]+['\"]",f"from '{cdn_url}'",content)files[file_key] = contentreturn fileselse:files = {'index.html': '','index.js': '','style.css': ''}else:files = {'index.html': '','index.js': '','style.css': ''}# Multiple patterns to match the three code blocks with different variationshtml_patterns = [
34 unmodified lines3536373839404120 unmodified lines6263646566676869707172737434 unmodified lines- Generating a README.md will break the deployment process**🚨 CRITICAL: Required Output Format**You MUST output ALL THREE files using this EXACT format with === markers:=== index.html ===<!DOCTYPE html>20 unmodified lines/* Your complete CSS styles here *//* Include all styling for the application */**CRITICAL FORMATTING RULES:**1. Start each file IMMEDIATELY after the === marker (on the next line)2. DO NOT use markdown code blocks (```html, ```javascript, ```css) - these will cause parsing errors3. DO NOT leave any file empty - each file MUST contain complete, functional code4. ONLY use the === filename === format shown above5. Make sure there is a blank line between each file section6. Each file must be complete and ready to deploy - no placeholders or comments like "// add code here"**Example of CORRECT format:**=== index.html ===34 unmodified lines353637383940414243444520 unmodified lines666768697071727374757677787980818283848586878889909192939434 unmodified lines- Generating a README.md will break the deployment process**🚨 CRITICAL: Required Output Format****THE VERY FIRST LINE of your response MUST be: === index.html ===**You MUST output ALL THREE files using this EXACT format with === markers.Your response must start IMMEDIATELY with the === index.html === marker.=== index.html ===<!DOCTYPE html>20 unmodified lines/* Your complete CSS styles here *//* Include all styling for the application */**🚨 CRITICAL FORMATTING RULES (MUST FOLLOW EXACTLY):**1. **FIRST LINE MUST BE: === index.html ===** (no explanations, no code before this)2. Start each file's code IMMEDIATELY on the line after the === marker3. **NEVER use markdown code blocks** (```html, ```javascript, ```css) - these will cause parsing errors4. **NEVER leave any file empty** - each file MUST contain complete, functional code5. **ONLY use the === filename === markers** - do not add any other formatting6. Add a blank line between each file section7. Each file must be complete and ready to deploy - no placeholders or "// TODO" comments**WRONG FORMAT (DO NOT DO THIS):**<!DOCTYPE html><html>...=== index.js ===...**CORRECT FORMAT (DO THIS):**=== index.html ===<!DOCTYPE html><html>...=== index.js ===...**Example of CORRECT format:**=== index.html ===
backend_parsers.py+60-5
backend_prompts.py+28-8