Spaces:
Running
Running
update
Browse files- backend_api.py +3 -30
- backend_parsers.py +0 -7
backend_api.py
CHANGED
|
@@ -520,37 +520,10 @@ def cleanup_generated_code(code: str, language: str) -> str:
|
|
| 520 |
try:
|
| 521 |
original_code = code
|
| 522 |
|
| 523 |
-
# Special handling for transformers.js -
|
|
|
|
| 524 |
if language == "transformers.js":
|
| 525 |
-
|
| 526 |
-
first_marker = code.find('===')
|
| 527 |
-
if first_marker == -1:
|
| 528 |
-
# No markers found, return as-is
|
| 529 |
-
return code
|
| 530 |
-
|
| 531 |
-
# Find the last code section end (after the last ===)
|
| 532 |
-
# Look for the last === marker
|
| 533 |
-
last_marker_start = code.rfind('===')
|
| 534 |
-
if last_marker_start == -1:
|
| 535 |
-
return code
|
| 536 |
-
|
| 537 |
-
# Find the end of the last code section
|
| 538 |
-
# This is typically followed by explanatory text starting with --- or multiple newlines
|
| 539 |
-
code_after_last_marker = code[last_marker_start:]
|
| 540 |
-
|
| 541 |
-
# Find where the actual code section ends (look for --- or excessive explanatory text)
|
| 542 |
-
end_markers = ['---', '\n\n\nThis ', '\n\n\n✨', '\n\n\n🎨', '\n\n\n🚀']
|
| 543 |
-
code_end = len(code)
|
| 544 |
-
|
| 545 |
-
for end_marker in end_markers:
|
| 546 |
-
pos = code.find(end_marker, last_marker_start)
|
| 547 |
-
if pos != -1 and pos < code_end:
|
| 548 |
-
code_end = pos
|
| 549 |
-
|
| 550 |
-
# Extract from first === to end of code
|
| 551 |
-
cleaned_code = code[first_marker:code_end].strip()
|
| 552 |
-
|
| 553 |
-
return cleaned_code
|
| 554 |
|
| 555 |
# Special handling for ComfyUI JSON
|
| 556 |
if language == "comfyui":
|
|
|
|
| 520 |
try:
|
| 521 |
original_code = code
|
| 522 |
|
| 523 |
+
# Special handling for transformers.js - don't clean, pass through as-is
|
| 524 |
+
# The parser will handle extracting the files from === markers
|
| 525 |
if language == "transformers.js":
|
| 526 |
+
return code
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 527 |
|
| 528 |
# Special handling for ComfyUI JSON
|
| 529 |
if language == "comfyui":
|
backend_parsers.py
CHANGED
|
@@ -18,13 +18,6 @@ def parse_transformers_js_output(code: str) -> Dict[str, str]:
|
|
| 18 |
print(f"[Parser] Received code length: {len(code)} characters")
|
| 19 |
print(f"[Parser] First 200 chars: {code[:200]}")
|
| 20 |
|
| 21 |
-
# Check if code has === markers
|
| 22 |
-
code_stripped = code.strip()
|
| 23 |
-
if '===' in code_stripped:
|
| 24 |
-
print("[Parser] Code contains === markers, proceeding with parsing")
|
| 25 |
-
else:
|
| 26 |
-
print("[Parser] WARNING: No === markers found in code")
|
| 27 |
-
|
| 28 |
# Check if code starts with HTML instead of markers (common LLM mistake)
|
| 29 |
if code_stripped.startswith('<!DOCTYPE') or code_stripped.startswith('<html'):
|
| 30 |
print("[Parser] WARNING: Code starts with HTML instead of === index.html === marker")
|
|
|
|
| 18 |
print(f"[Parser] Received code length: {len(code)} characters")
|
| 19 |
print(f"[Parser] First 200 chars: {code[:200]}")
|
| 20 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 21 |
# Check if code starts with HTML instead of markers (common LLM mistake)
|
| 22 |
if code_stripped.startswith('<!DOCTYPE') or code_stripped.startswith('<html'):
|
| 23 |
print("[Parser] WARNING: Code starts with HTML instead of === index.html === marker")
|