Spaces:
Running
Running
fix
Browse files- backend_deploy.py +19 -3
- backend_prompts.py +2 -0
backend_deploy.py
CHANGED
|
@@ -920,7 +920,13 @@ def deploy_to_huggingface_space(
|
|
| 920 |
for filename, content in files.items():
|
| 921 |
file_path = temp_path / filename
|
| 922 |
print(f"[Deploy] Writing {filename} ({len(content)} chars) to {file_path}")
|
| 923 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 924 |
# Verify the write was successful
|
| 925 |
written_size = file_path.stat().st_size
|
| 926 |
print(f"[Deploy] Verified {filename}: {written_size} bytes on disk")
|
|
@@ -1143,6 +1149,15 @@ def deploy_to_huggingface_space(
|
|
| 1143 |
if not file_content:
|
| 1144 |
return False, f"Missing content for {file_name}", None
|
| 1145 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1146 |
success = False
|
| 1147 |
last_error = None
|
| 1148 |
|
|
@@ -1151,8 +1166,9 @@ def deploy_to_huggingface_space(
|
|
| 1151 |
try:
|
| 1152 |
# Create a NEW temp file for this upload (key difference from old approach)
|
| 1153 |
print(f"[Deploy] Creating temp file for {file_name} with {len(file_content)} chars")
|
| 1154 |
-
|
| 1155 |
-
|
|
|
|
| 1156 |
f.flush() # Ensure all content is written to disk before closing
|
| 1157 |
temp_file_path = f.name
|
| 1158 |
# File is now closed and flushed, safe to upload
|
|
|
|
| 920 |
for filename, content in files.items():
|
| 921 |
file_path = temp_path / filename
|
| 922 |
print(f"[Deploy] Writing {filename} ({len(content)} chars) to {file_path}")
|
| 923 |
+
# Use binary mode with UTF-8 encoding for better emoji/special character handling
|
| 924 |
+
try:
|
| 925 |
+
file_path.write_bytes(content.encode('utf-8'))
|
| 926 |
+
except UnicodeEncodeError as e:
|
| 927 |
+
print(f"[Deploy] Encoding error in {filename}: {e}, using fallback encoding")
|
| 928 |
+
# Fallback: ignore problematic characters
|
| 929 |
+
file_path.write_bytes(content.encode('utf-8', errors='ignore'))
|
| 930 |
# Verify the write was successful
|
| 931 |
written_size = file_path.stat().st_size
|
| 932 |
print(f"[Deploy] Verified {filename}: {written_size} bytes on disk")
|
|
|
|
| 1149 |
if not file_content:
|
| 1150 |
return False, f"Missing content for {file_name}", None
|
| 1151 |
|
| 1152 |
+
# Ensure content is properly encoded (handle emojis safely)
|
| 1153 |
+
try:
|
| 1154 |
+
# Test encoding - this will catch any encoding issues early
|
| 1155 |
+
file_content.encode('utf-8', errors='strict')
|
| 1156 |
+
except UnicodeEncodeError as e:
|
| 1157 |
+
print(f"[Deploy] Encoding warning for {file_name}: {e}")
|
| 1158 |
+
# Replace problematic characters with safe equivalents
|
| 1159 |
+
file_content = file_content.encode('utf-8', errors='ignore').decode('utf-8')
|
| 1160 |
+
|
| 1161 |
success = False
|
| 1162 |
last_error = None
|
| 1163 |
|
|
|
|
| 1166 |
try:
|
| 1167 |
# Create a NEW temp file for this upload (key difference from old approach)
|
| 1168 |
print(f"[Deploy] Creating temp file for {file_name} with {len(file_content)} chars")
|
| 1169 |
+
# Use binary mode with explicit UTF-8 encoding for better emoji handling
|
| 1170 |
+
with tempfile.NamedTemporaryFile("wb", suffix=f".{file_name.split('.')[-1]}", delete=False) as f:
|
| 1171 |
+
f.write(file_content.encode('utf-8'))
|
| 1172 |
f.flush() # Ensure all content is written to disk before closing
|
| 1173 |
temp_file_path = f.name
|
| 1174 |
# File is now closed and flushed, safe to upload
|
backend_prompts.py
CHANGED
|
@@ -74,6 +74,7 @@ import { pipeline } from 'https://cdn.jsdelivr.net/npm/@huggingface/transformers
|
|
| 74 |
5. **ONLY use the === filename === markers** - do not add any other formatting
|
| 75 |
6. Add a blank line between each file section
|
| 76 |
7. Each file must be complete and ready to deploy - no placeholders or "// TODO" comments
|
|
|
|
| 77 |
|
| 78 |
**WRONG FORMAT (DO NOT DO THIS):**
|
| 79 |
<!DOCTYPE html>
|
|
@@ -176,6 +177,7 @@ Consider providing users with options to choose device (CPU/GPU) and quantizatio
|
|
| 176 |
3. ALL THREE files must be complete and functional - no placeholders or "TODO" comments
|
| 177 |
4. Start each file's content immediately on the line after the === marker
|
| 178 |
5. Ensure each file has actual content - empty files will cause deployment failure
|
|
|
|
| 179 |
|
| 180 |
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"""
|
| 181 |
|
|
|
|
| 74 |
5. **ONLY use the === filename === markers** - do not add any other formatting
|
| 75 |
6. Add a blank line between each file section
|
| 76 |
7. Each file must be complete and ready to deploy - no placeholders or "// TODO" comments
|
| 77 |
+
8. **AVOID EMOJIS in the generated code** (HTML/JS/CSS files) - use text or unicode symbols instead for deployment compatibility
|
| 78 |
|
| 79 |
**WRONG FORMAT (DO NOT DO THIS):**
|
| 80 |
<!DOCTYPE html>
|
|
|
|
| 177 |
3. ALL THREE files must be complete and functional - no placeholders or "TODO" comments
|
| 178 |
4. Start each file's content immediately on the line after the === marker
|
| 179 |
5. Ensure each file has actual content - empty files will cause deployment failure
|
| 180 |
+
6. AVOID using emojis in the generated code files - use text or HTML entities instead
|
| 181 |
|
| 182 |
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"""
|
| 183 |
|