Spaces:
Running
Running
Commit
·
30684c6
1
Parent(s):
2ad4034
Simplify HTML cleaning to fix 500 error - use basic string replacement instead of BeautifulSoup
Browse files
app.py
CHANGED
|
@@ -67,29 +67,8 @@ def render_preview(code: str, width: int, height: int, scale: float) -> str:
|
|
| 67 |
"""
|
| 68 |
Preview renderer with both width and height control for the inner canvas.
|
| 69 |
"""
|
| 70 |
-
#
|
| 71 |
-
|
| 72 |
-
|
| 73 |
-
# Remove any script tags that reference local assets or iframeResizer
|
| 74 |
-
for script in soup.find_all('script'):
|
| 75 |
-
src = script.get('src', '')
|
| 76 |
-
if src and ('assets/' in src or 'index-' in src or 'iframeResizer' in src):
|
| 77 |
-
script.decompose()
|
| 78 |
-
|
| 79 |
-
# Remove any link tags that reference local CSS assets
|
| 80 |
-
for link in soup.find_all('link'):
|
| 81 |
-
href = link.get('href', '')
|
| 82 |
-
if href and ('assets/' in href or 'index-' in href):
|
| 83 |
-
link.decompose()
|
| 84 |
-
|
| 85 |
-
# Also remove any inline scripts that might contain problematic content
|
| 86 |
-
for script in soup.find_all('script'):
|
| 87 |
-
if script.string and ('assets/' in script.string or 'index-' in script.string):
|
| 88 |
-
script.decompose()
|
| 89 |
-
|
| 90 |
-
# Get the cleaned HTML
|
| 91 |
-
cleaned_code = str(soup)
|
| 92 |
-
safe_code = html.escape(cleaned_code).replace("'", "'")
|
| 93 |
|
| 94 |
iframe_html = f"""
|
| 95 |
<div style="width: 100%; max-width: 1920px; margin: 0 auto; overflow-x: auto; overflow-y: hidden;">
|
|
@@ -155,24 +134,10 @@ def process_and_generate(image_np, image_path_from_state, sidebar_prompt, header
|
|
| 155 |
|
| 156 |
print(f"Processing HTML for run_id: {run_id}")
|
| 157 |
|
| 158 |
-
#
|
| 159 |
-
|
| 160 |
-
|
| 161 |
-
|
| 162 |
-
print(f"Removing problematic script: {src}")
|
| 163 |
-
script.decompose()
|
| 164 |
-
|
| 165 |
-
for link in soup.find_all('link'):
|
| 166 |
-
href = link.get('href', '')
|
| 167 |
-
if href and ('assets/' in href or 'index-' in href):
|
| 168 |
-
print(f"Removing problematic CSS link: {href}")
|
| 169 |
-
link.decompose()
|
| 170 |
-
|
| 171 |
-
# Also remove any inline scripts that might contain problematic content
|
| 172 |
-
for script in soup.find_all('script'):
|
| 173 |
-
if script.string and ('assets/' in script.string or 'index-' in script.string):
|
| 174 |
-
print(f"Removing problematic inline script")
|
| 175 |
-
script.decompose()
|
| 176 |
|
| 177 |
for img in soup.find_all('img'):
|
| 178 |
if img.get('src') and not img['src'].startswith(('http', 'data:')):
|
|
|
|
| 67 |
"""
|
| 68 |
Preview renderer with both width and height control for the inner canvas.
|
| 69 |
"""
|
| 70 |
+
# Simple HTML escaping for now to avoid potential issues
|
| 71 |
+
safe_code = html.escape(code).replace("'", "'")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 72 |
|
| 73 |
iframe_html = f"""
|
| 74 |
<div style="width: 100%; max-width: 1920px; margin: 0 auto; overflow-x: auto; overflow-y: hidden;">
|
|
|
|
| 134 |
|
| 135 |
print(f"Processing HTML for run_id: {run_id}")
|
| 136 |
|
| 137 |
+
# Simple cleanup for now - just remove obvious problematic references
|
| 138 |
+
html_content = html_content.replace('index-BQPjLIsY.js', '')
|
| 139 |
+
html_content = html_content.replace('index-BOW2xVAS.css', '')
|
| 140 |
+
html_content = html_content.replace('iframeResizer', '')
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 141 |
|
| 142 |
for img in soup.find_all('img'):
|
| 143 |
if img.get('src') and not img['src'].startswith(('http', 'data:')):
|