Spaces:
Paused
Paused
Commit
·
d428c88
1
Parent(s):
c6373cc
Add aggressive string-based cleanup to remove all problematic asset references
Browse files
app.py
CHANGED
|
@@ -85,6 +85,13 @@ def render_preview(code: str, width: int, height: int, scale: float) -> str:
|
|
| 85 |
|
| 86 |
# Get the cleaned HTML
|
| 87 |
cleaned_code = str(soup)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 88 |
except Exception as e:
|
| 89 |
print(f"Error cleaning HTML in render_preview: {e}")
|
| 90 |
# Fallback to original code if cleaning fails
|
|
@@ -168,6 +175,17 @@ def process_and_generate(image_np, image_path_from_state, sidebar_prompt, header
|
|
| 168 |
if href and any(pattern in href for pattern in ['assets/', 'index-']):
|
| 169 |
print(f"Removing problematic CSS link: {href}")
|
| 170 |
link.decompose()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 171 |
except Exception as e:
|
| 172 |
print(f"Error cleaning HTML in process_and_generate: {e}")
|
| 173 |
|
|
|
|
| 85 |
|
| 86 |
# Get the cleaned HTML
|
| 87 |
cleaned_code = str(soup)
|
| 88 |
+
|
| 89 |
+
# Additional string-based cleanup for any remaining references
|
| 90 |
+
cleaned_code = cleaned_code.replace('index-BQPjLISY.js', '')
|
| 91 |
+
cleaned_code = cleaned_code.replace('index-BOW2xVAS.css', '')
|
| 92 |
+
cleaned_code = cleaned_code.replace('./assets/', '')
|
| 93 |
+
cleaned_code = cleaned_code.replace('assets/', '')
|
| 94 |
+
|
| 95 |
except Exception as e:
|
| 96 |
print(f"Error cleaning HTML in render_preview: {e}")
|
| 97 |
# Fallback to original code if cleaning fails
|
|
|
|
| 175 |
if href and any(pattern in href for pattern in ['assets/', 'index-']):
|
| 176 |
print(f"Removing problematic CSS link: {href}")
|
| 177 |
link.decompose()
|
| 178 |
+
|
| 179 |
+
# Additional string-based cleanup for any remaining references
|
| 180 |
+
html_content = str(soup)
|
| 181 |
+
html_content = html_content.replace('index-BQPjLISY.js', '')
|
| 182 |
+
html_content = html_content.replace('index-BOW2xVAS.css', '')
|
| 183 |
+
html_content = html_content.replace('./assets/', '')
|
| 184 |
+
html_content = html_content.replace('assets/', '')
|
| 185 |
+
|
| 186 |
+
# Re-parse the cleaned HTML
|
| 187 |
+
soup = BeautifulSoup(html_content, 'html.parser')
|
| 188 |
+
|
| 189 |
except Exception as e:
|
| 190 |
print(f"Error cleaning HTML in process_and_generate: {e}")
|
| 191 |
|