Spaces:
Running
Running
Commit
·
3d608a7
1
Parent(s):
ff47789
Fix Gradio theme and cache issues to resolve 'Content unavailable' error
Browse files
app.py
CHANGED
|
@@ -68,32 +68,36 @@ def patch_css_js_paths(soup: BeautifulSoup, output_dir: Path):
|
|
| 68 |
Fix CSS and JS paths in the HTML to work with Gradio's file serving.
|
| 69 |
Converts relative paths to /file= paths or removes them if files don't exist.
|
| 70 |
"""
|
| 71 |
-
|
| 72 |
-
|
| 73 |
-
|
| 74 |
-
|
| 75 |
-
|
| 76 |
-
|
| 77 |
-
|
| 78 |
-
|
| 79 |
-
|
| 80 |
-
|
| 81 |
-
|
| 82 |
-
|
|
|
|
| 83 |
|
| 84 |
-
|
| 85 |
-
|
| 86 |
-
|
| 87 |
-
|
| 88 |
-
|
| 89 |
-
|
| 90 |
-
|
| 91 |
-
|
| 92 |
-
|
| 93 |
-
|
| 94 |
-
|
| 95 |
-
|
| 96 |
|
|
|
|
|
|
|
|
|
|
| 97 |
return soup
|
| 98 |
|
| 99 |
def render_preview(code: str, width: int, height: int, scale: float) -> str:
|
|
@@ -236,7 +240,7 @@ def process_and_generate(image_np, image_path_from_state, sidebar_prompt, header
|
|
| 236 |
|
| 237 |
return initial_preview, html_content, gr.update(value=package_url, visible=True)
|
| 238 |
|
| 239 |
-
with gr.Blocks(head=TAILWIND_SCRIPT, theme=gr.themes.
|
| 240 |
gr.Markdown("# ScreenCoder: Screenshot to Code")
|
| 241 |
with gr.Row():
|
| 242 |
with gr.Column(scale=1):
|
|
@@ -330,4 +334,12 @@ for path in allowed_paths:
|
|
| 330 |
print(f" - {path}")
|
| 331 |
|
| 332 |
if __name__ == "__main__":
|
| 333 |
-
demo.launch(
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 68 |
Fix CSS and JS paths in the HTML to work with Gradio's file serving.
|
| 69 |
Converts relative paths to /file= paths or removes them if files don't exist.
|
| 70 |
"""
|
| 71 |
+
try:
|
| 72 |
+
# CSS
|
| 73 |
+
for link in soup.find_all("link", rel=lambda x: x and "stylesheet" in x):
|
| 74 |
+
href = link.get("href", "")
|
| 75 |
+
if href.startswith(("http", "data:")):
|
| 76 |
+
continue
|
| 77 |
+
f = output_dir / href.lstrip("./")
|
| 78 |
+
if f.exists():
|
| 79 |
+
link["href"] = f"/file={f}"
|
| 80 |
+
print(f"Fixed CSS path: {href} -> /file={f}")
|
| 81 |
+
else:
|
| 82 |
+
print(f"Removing non-existent CSS: {href}")
|
| 83 |
+
link.decompose()
|
| 84 |
|
| 85 |
+
# JS
|
| 86 |
+
for script in soup.find_all("script", src=True):
|
| 87 |
+
src = script["src"]
|
| 88 |
+
if src.startswith(("http", "data:")):
|
| 89 |
+
continue
|
| 90 |
+
f = output_dir / src.lstrip("./")
|
| 91 |
+
if f.exists():
|
| 92 |
+
script["src"] = f"/file={f}"
|
| 93 |
+
print(f"Fixed JS path: {src} -> /file={f}")
|
| 94 |
+
else:
|
| 95 |
+
print(f"Removing non-existent JS: {src}")
|
| 96 |
+
script.decompose()
|
| 97 |
|
| 98 |
+
except Exception as e:
|
| 99 |
+
print(f"Error in patch_css_js_paths: {e}")
|
| 100 |
+
|
| 101 |
return soup
|
| 102 |
|
| 103 |
def render_preview(code: str, width: int, height: int, scale: float) -> str:
|
|
|
|
| 240 |
|
| 241 |
return initial_preview, html_content, gr.update(value=package_url, visible=True)
|
| 242 |
|
| 243 |
+
with gr.Blocks(head=TAILWIND_SCRIPT, theme=gr.themes.Default()) as demo:
|
| 244 |
gr.Markdown("# ScreenCoder: Screenshot to Code")
|
| 245 |
with gr.Row():
|
| 246 |
with gr.Column(scale=1):
|
|
|
|
| 334 |
print(f" - {path}")
|
| 335 |
|
| 336 |
if __name__ == "__main__":
|
| 337 |
+
demo.launch(
|
| 338 |
+
allowed_paths=allowed_paths,
|
| 339 |
+
show_error=True,
|
| 340 |
+
quiet=False,
|
| 341 |
+
favicon_path=None,
|
| 342 |
+
prevent_thread_lock=True,
|
| 343 |
+
cache_examples=False,
|
| 344 |
+
show_tips=False
|
| 345 |
+
)
|