Spaces:
Running
Running
feat: enhance HTML preview styling and fix content handling
Browse files
app.py
CHANGED
|
@@ -4,7 +4,7 @@ import re
|
|
| 4 |
import anthropic
|
| 5 |
import os
|
| 6 |
from dotenv import load_dotenv
|
| 7 |
-
from utils import svg_to_png_base64
|
| 8 |
import pathlib
|
| 9 |
from logger import setup_logger
|
| 10 |
import html
|
|
@@ -558,22 +558,22 @@ def create_animation_preview(animation_desc: str, svg_content: str) -> tuple:
|
|
| 558 |
print(f"Animation preview saved to: {html_path}")
|
| 559 |
|
| 560 |
# Create iframe HTML - only escape quotes for srcdoc attribute
|
| 561 |
-
|
|
|
|
|
|
|
| 562 |
preview_html = f"""
|
| 563 |
-
<div style='padding: 20px; background: #fff; border: 1px solid #eee; border-radius: 8px;
|
| 564 |
-
<div style='
|
| 565 |
-
|
| 566 |
-
|
| 567 |
-
|
| 568 |
-
width="100%" height="600px"
|
| 569 |
-
style="border:none; overflow:hidden;"
|
| 570 |
sandbox="allow-scripts allow-same-origin">
|
| 571 |
</iframe>
|
| 572 |
</div>
|
| 573 |
</div>
|
| 574 |
"""
|
| 575 |
|
| 576 |
-
return preview_html,
|
| 577 |
|
| 578 |
except Exception as e:
|
| 579 |
error_html = create_error_html(f"❌ Error creating animation: {str(e)}")
|
|
@@ -641,7 +641,9 @@ with demo:
|
|
| 641 |
|
| 642 |
# Add dropdown change event
|
| 643 |
example_dropdown.change(
|
| 644 |
-
fn=load_example,
|
|
|
|
|
|
|
| 645 |
)
|
| 646 |
|
| 647 |
process_btn = gr.Button("🔄 Decompose Structure", variant="primary")
|
|
|
|
| 4 |
import anthropic
|
| 5 |
import os
|
| 6 |
from dotenv import load_dotenv
|
| 7 |
+
from utils import svg_to_png_base64, fix_html_styles_for_preview
|
| 8 |
import pathlib
|
| 9 |
from logger import setup_logger
|
| 10 |
import html
|
|
|
|
| 558 |
print(f"Animation preview saved to: {html_path}")
|
| 559 |
|
| 560 |
# Create iframe HTML - only escape quotes for srcdoc attribute
|
| 561 |
+
fixed_html_content = fix_html_styles_for_preview(html_content)
|
| 562 |
+
safe_html_content = fixed_html_content.replace('"', """)
|
| 563 |
+
|
| 564 |
preview_html = f"""
|
| 565 |
+
<div style='padding: 20px; width:100%; background: #fff; border: 1px solid #eee; border-radius: 8px; position: relative;'>
|
| 566 |
+
<div style='border:1px solid #ddd; border-radius:8px; background:#fafafa; display:flex; align-items:center; justify-content:center; padding:20px; position:relative; box-sizing:border-box;'>
|
| 567 |
+
<iframe
|
| 568 |
+
srcdoc="{safe_html_content}"
|
| 569 |
+
style="width: 360px; height: 360px; border:none; border-radius:8px; overflow:hidden;"
|
|
|
|
|
|
|
| 570 |
sandbox="allow-scripts allow-same-origin">
|
| 571 |
</iframe>
|
| 572 |
</div>
|
| 573 |
</div>
|
| 574 |
"""
|
| 575 |
|
| 576 |
+
return preview_html, fixed_html_content
|
| 577 |
|
| 578 |
except Exception as e:
|
| 579 |
error_html = create_error_html(f"❌ Error creating animation: {str(e)}")
|
|
|
|
| 641 |
|
| 642 |
# Add dropdown change event
|
| 643 |
example_dropdown.change(
|
| 644 |
+
fn=load_example,
|
| 645 |
+
inputs=[example_dropdown],
|
| 646 |
+
outputs=[svg_file, object_name],
|
| 647 |
)
|
| 648 |
|
| 649 |
process_btn = gr.Button("🔄 Decompose Structure", variant="primary")
|