Fix transformers.js parser: Support both === and markdown formats
Browse filesIssue: LLM was generating code with markdown blocks (html, javascript, css)
but parser only looked for === filename === format
Fixes:
1. Updated TRANSFORMERS_JS_SYSTEM_PROMPT to specify === format explicitly
- Added clear examples showing === index.html ===, === index.js ===, === style.css ===
- Explicitly stated NOT to use markdown code blocks
2. Enhanced parse_transformers_js_output() with fallback logic:
- Primary: Parse === filename === sections
- Fallback: Parse markdown code blocks (html, javascript, css)
- Last resort: Try single HTML file extraction
- Removes placeholder comments from extracted content
This ensures backward compatibility with already-generated code while
guiding future generations to use the correct format.
Files changed (2)
- backend_deploy.py+51-5
- backend_prompts.py+11-7
39 unmodified lines40414243434445467 unmodified lines5455565758596061626364656667686970717273747576777879808182835784858687267 unmodified lines35535635733133233335835936036136236336436536636736836937037137237337437537637737837938038138239 unmodified lines """Parse transformers.js output into separate files""" files = {} # Pattern to match file sections # First try: Pattern to match === filename === sections pattern = r'===\s*(\S+\.(?:html|js|css))\s*===\s*(.*?)(?====|$)' matches = re.finditer(pattern, code, re.DOTALL | re.IGNORECASE) 7 unmodified lines files[filename] = content # Fallback: Try to extract from markdown code blocks if === format not found if not files: print("[Deploy] === format not found, trying markdown code blocks fallback") # Try to find ```html, ```javascript, ```css blocks html_match = re.search(r'```html\s*(.*?)```', code, re.DOTALL | re.IGNORECASE) js_match = re.search(r'```javascript\s*(.*?)```', code, re.DOTALL | re.IGNORECASE) css_match = re.search(r'```css\s*(.*?)```', code, re.DOTALL | re.IGNORECASE) if html_match: content = html_match.group(1).strip() # Remove comment lines like "<!-- index.html content here -->" content = re.sub(r'<!--\s*index\.html.*?-->\s*', '', content, flags=re.IGNORECASE) files['index.html'] = content if js_match: content = js_match.group(1).strip() # Remove comment lines like "// index.js content here" content = re.sub(r'//\s*index\.js.*?\n', '', content, flags=re.IGNORECASE) files['index.js'] = content if css_match: content = css_match.group(1).strip() # Remove comment lines like "/* style.css content here */" content = re.sub(r'/\*\s*style\.css.*?\*/', '', content, flags=re.IGNORECASE) files['style.css'] = content # If no files were parsed, try to extract as single HTML file # Last resort: try to extract as single HTML file if not files: html_content = parse_html_code(code) if html_content:267 unmodified lines files = parse_transformers_js_output(code) print(f"[Deploy] Parsed transformers.js files: {list(files.keys())}") # Validate all three files are present (match original deploy.py check) if not files['index.html'] or not files['index.js'] or not files['style.css']: return False, "Error: Could not parse transformers.js output. Please regenerate the code.", None # Validate all three files are present missing_files = [] if not files.get('index.html'): missing_files.append('index.html') if not files.get('index.js'): missing_files.append('index.js') if not files.get('style.css'): missing_files.append('style.css') if missing_files: error_msg = f"Missing required files: {', '.join(missing_files)}. " error_msg += f"Found only: {', '.join(files.keys()) if files else 'no files'}. " error_msg += "Transformers.js apps require all three files with === filename === markers. Please regenerate the code." print(f"[Deploy] {error_msg}") return False, error_msg, None # Validate files have content empty_files = [name for name, content in files.items() if not content or not content.strip()] if empty_files: error_msg = f"Empty files detected: {', '.join(empty_files)}. Please regenerate the code with actual content." print(f"[Deploy] {error_msg}") return False, error_msg, None # Write transformers.js files for filename, content in files.items():25 unmodified lines26272829293031313233343533363735383937403941424143444546474825 unmodified lines- A template README.md is automatically provided and will be overridden by the deployment system- Generating a README.md will break the deployment process
IMPORTANT: You MUST output ALL THREE files in the following format:**🚨 CRITICAL: Required Output Format**You MUST output ALL THREE files using this EXACT format with === markers:
```html=== index.html ===<!DOCTYPE html><html lang="en"><!-- index.html content here -->```</html>
```javascript=== index.js ===// index.js content here```
```css=== style.css ===/* style.css content here */```
DO NOT use markdown code blocks (```html, ```javascript, ```css).ONLY use the === filename === format shown above.
Requirements:1. Create a modern, responsive web application using transformers.jsbackend_deploy.py+51-5
backend_prompts.py+11-7