Spaces:
Running
Running
fix transforemrs js issue
Browse files- backend_parsers.py +19 -7
- backend_prompts.py +50 -10
backend_parsers.py
CHANGED
|
@@ -62,17 +62,29 @@ def parse_transformers_js_output(code: str) -> Dict[str, str]:
|
|
| 62 |
|
| 63 |
# Fallback: support === index.html === format if any file is missing
|
| 64 |
if not (files['index.html'] and files['index.js'] and files['style.css']):
|
| 65 |
-
# Use regex to extract sections
|
| 66 |
-
html_fallback = re.search(r'===\s*index\.html\s*===\s
|
| 67 |
-
js_fallback = re.search(r'===\s*index\.js\s*===\s
|
| 68 |
-
css_fallback = re.search(r'===\s*style\.css\s*===\s
|
| 69 |
|
| 70 |
if html_fallback:
|
| 71 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 72 |
if js_fallback:
|
| 73 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 74 |
if css_fallback:
|
| 75 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 76 |
|
| 77 |
# Additional fallback: extract from numbered sections or file headers
|
| 78 |
if not (files['index.html'] and files['index.js'] and files['style.css']):
|
|
|
|
| 62 |
|
| 63 |
# Fallback: support === index.html === format if any file is missing
|
| 64 |
if not (files['index.html'] and files['index.js'] and files['style.css']):
|
| 65 |
+
# Use regex to extract sections - match === markers with optional whitespace and newlines
|
| 66 |
+
html_fallback = re.search(r'===\s*index\.html\s*===\s*[\r\n]+([\s\S]+?)(?=\n===|$)', code, re.IGNORECASE)
|
| 67 |
+
js_fallback = re.search(r'===\s*index\.js\s*===\s*[\r\n]+([\s\S]+?)(?=\n===|$)', code, re.IGNORECASE)
|
| 68 |
+
css_fallback = re.search(r'===\s*style\.css\s*===\s*[\r\n]+([\s\S]+?)(?=\n===|$)', code, re.IGNORECASE)
|
| 69 |
|
| 70 |
if html_fallback:
|
| 71 |
+
content = html_fallback.group(1).strip()
|
| 72 |
+
# Remove code block markers if present
|
| 73 |
+
content = re.sub(r'^```\w*\s*[\r\n]+', '', content)
|
| 74 |
+
content = re.sub(r'[\r\n]+```\s*$', '', content)
|
| 75 |
+
files['index.html'] = content.strip()
|
| 76 |
if js_fallback:
|
| 77 |
+
content = js_fallback.group(1).strip()
|
| 78 |
+
# Remove code block markers if present
|
| 79 |
+
content = re.sub(r'^```\w*\s*[\r\n]+', '', content)
|
| 80 |
+
content = re.sub(r'[\r\n]+```\s*$', '', content)
|
| 81 |
+
files['index.js'] = content.strip()
|
| 82 |
if css_fallback:
|
| 83 |
+
content = css_fallback.group(1).strip()
|
| 84 |
+
# Remove code block markers if present
|
| 85 |
+
content = re.sub(r'^```\w*\s*[\r\n]+', '', content)
|
| 86 |
+
content = re.sub(r'[\r\n]+```\s*$', '', content)
|
| 87 |
+
files['style.css'] = content.strip()
|
| 88 |
|
| 89 |
# Additional fallback: extract from numbered sections or file headers
|
| 90 |
if not (files['index.html'] and files['index.js'] and files['style.css']):
|
backend_prompts.py
CHANGED
|
@@ -40,17 +40,51 @@ You MUST output ALL THREE files using this EXACT format with === markers:
|
|
| 40 |
=== index.html ===
|
| 41 |
<!DOCTYPE html>
|
| 42 |
<html lang="en">
|
| 43 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 44 |
</html>
|
| 45 |
|
| 46 |
=== index.js ===
|
| 47 |
-
|
|
|
|
|
|
|
|
|
|
| 48 |
|
| 49 |
=== style.css ===
|
| 50 |
-
/*
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 51 |
|
| 52 |
-
|
| 53 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 54 |
|
| 55 |
Requirements:
|
| 56 |
1. Create a modern, responsive web application using transformers.js
|
|
@@ -111,11 +145,17 @@ const pipe = await pipeline('sentiment-analysis', 'Xenova/distilbert-base-uncase
|
|
| 111 |
|
| 112 |
Consider providing users with options to choose device (CPU/GPU) and quantization level based on their needs.
|
| 113 |
|
| 114 |
-
|
| 115 |
-
|
| 116 |
-
|
| 117 |
-
|
| 118 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 119 |
|
| 120 |
IMPORTANT: Always include "Built with anycoder" as clickable text in the header/top section of your application that links to https://huggingface.co/spaces/akhaliq/anycoder"""
|
| 121 |
|
|
|
|
| 40 |
=== index.html ===
|
| 41 |
<!DOCTYPE html>
|
| 42 |
<html lang="en">
|
| 43 |
+
<head>
|
| 44 |
+
<meta charset="UTF-8">
|
| 45 |
+
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
| 46 |
+
<title>Your App Title</title>
|
| 47 |
+
<link rel="stylesheet" href="style.css">
|
| 48 |
+
</head>
|
| 49 |
+
<body>
|
| 50 |
+
<!-- Your complete HTML content here -->
|
| 51 |
+
<script type="module" src="index.js"></script>
|
| 52 |
+
</body>
|
| 53 |
</html>
|
| 54 |
|
| 55 |
=== index.js ===
|
| 56 |
+
import { pipeline } from 'https://cdn.jsdelivr.net/npm/@huggingface/transformers@3.8.0';
|
| 57 |
+
|
| 58 |
+
// Your complete JavaScript code here
|
| 59 |
+
// Include all functionality, event listeners, and logic
|
| 60 |
|
| 61 |
=== style.css ===
|
| 62 |
+
/* Your complete CSS styles here */
|
| 63 |
+
/* Include all styling for the application */
|
| 64 |
+
|
| 65 |
+
**CRITICAL FORMATTING RULES:**
|
| 66 |
+
1. Start each file IMMEDIATELY after the === marker (on the next line)
|
| 67 |
+
2. DO NOT use markdown code blocks (```html, ```javascript, ```css) - these will cause parsing errors
|
| 68 |
+
3. DO NOT leave any file empty - each file MUST contain complete, functional code
|
| 69 |
+
4. ONLY use the === filename === format shown above
|
| 70 |
+
5. Make sure there is a blank line between each file section
|
| 71 |
+
6. Each file must be complete and ready to deploy - no placeholders or comments like "// add code here"
|
| 72 |
+
|
| 73 |
+
**Example of CORRECT format:**
|
| 74 |
+
=== index.html ===
|
| 75 |
+
<!DOCTYPE html>
|
| 76 |
+
<html>
|
| 77 |
+
<head>...</head>
|
| 78 |
+
<body>...</body>
|
| 79 |
+
</html>
|
| 80 |
|
| 81 |
+
=== index.js ===
|
| 82 |
+
import { pipeline } from '...';
|
| 83 |
+
// Complete working code
|
| 84 |
+
|
| 85 |
+
=== style.css ===
|
| 86 |
+
body { margin: 0; }
|
| 87 |
+
/* Complete styling */
|
| 88 |
|
| 89 |
Requirements:
|
| 90 |
1. Create a modern, responsive web application using transformers.js
|
|
|
|
| 145 |
|
| 146 |
Consider providing users with options to choose device (CPU/GPU) and quantization level based on their needs.
|
| 147 |
|
| 148 |
+
**File Content Requirements:**
|
| 149 |
+
- **index.html**: Complete HTML structure with proper DOCTYPE, meta tags, links to CSS/JS files, and full body content
|
| 150 |
+
- **index.js**: Complete JavaScript logic with transformers.js imports and ALL functionality implemented
|
| 151 |
+
- **style.css**: Complete styling for the entire application - NO empty or placeholder styles
|
| 152 |
+
|
| 153 |
+
**🚨 FINAL REMINDERS:**
|
| 154 |
+
1. Use the === filename === markers EXACTLY as shown in the examples
|
| 155 |
+
2. DO NOT use markdown code blocks (```html, ```js, ```css)
|
| 156 |
+
3. ALL THREE files must be complete and functional - no placeholders or "TODO" comments
|
| 157 |
+
4. Start each file's content immediately on the line after the === marker
|
| 158 |
+
5. Ensure each file has actual content - empty files will cause deployment failure
|
| 159 |
|
| 160 |
IMPORTANT: Always include "Built with anycoder" as clickable text in the header/top section of your application that links to https://huggingface.co/spaces/akhaliq/anycoder"""
|
| 161 |
|