Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
|
@@ -713,21 +713,28 @@ Now provide the result directly.
|
|
| 713 |
# When creating the iframe, properly escape single quotes in the srcdoc attribute
|
| 714 |
result = result.strip().strip("```").strip()
|
| 715 |
|
| 716 |
-
#
|
| 717 |
-
|
|
|
|
| 718 |
|
| 719 |
-
# Create
|
| 720 |
-
htmloutput = f"""
|
| 721 |
-
<
|
| 722 |
-
|
| 723 |
-
|
| 724 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 725 |
|
| 726 |
-
logging.info(f"The code produced for this graph placeholder:\n{placeholder_text}
|
| 727 |
return htmloutput
|
| 728 |
|
| 729 |
def replace_graph_placeholders(report_html: str, context: str, initial_query: str, crumbs: str) -> str:
|
| 730 |
-
pattern = r"\[\[Graph Placeholder (\d+):(.*?)\]\]"
|
| 731 |
|
| 732 |
def placeholder_replacer(match):
|
| 733 |
placeholder_num = match.group(1)
|
|
@@ -736,11 +743,11 @@ def replace_graph_placeholders(report_html: str, context: str, initial_query: st
|
|
| 736 |
|
| 737 |
try:
|
| 738 |
visual_html = generate_graph_snippet(instructions, context, initial_query, crumbs)
|
| 739 |
-
|
| 740 |
-
return f'<div class="graph-wrapper">\n<!-- Graph {placeholder_num} Start -->\n{visual_html}\n<!-- Graph {placeholder_num} End -->\n</div>'
|
| 741 |
except Exception as e:
|
| 742 |
logging.error(f"Graph {placeholder_num} failed: {str(e)}")
|
| 743 |
-
|
|
|
|
| 744 |
|
| 745 |
return re.sub(pattern, placeholder_replacer, report_html, flags=re.DOTALL)
|
| 746 |
|
|
|
|
| 713 |
# When creating the iframe, properly escape single quotes in the srcdoc attribute
|
| 714 |
result = result.strip().strip("```").strip()
|
| 715 |
|
| 716 |
+
# Properly escape the HTML content for srcdoc attribute
|
| 717 |
+
# Replace single quotes with HTML entities to avoid breaking the srcdoc attribute
|
| 718 |
+
escaped_content = result.replace("'", "'").replace('"', """)
|
| 719 |
|
| 720 |
+
# Create a responsive container with proper width constraints
|
| 721 |
+
htmloutput = f"""
|
| 722 |
+
<div class="d3-visualization" style="width:100%; max-width:1400px; margin:0 auto; overflow:hidden;">
|
| 723 |
+
<iframe
|
| 724 |
+
class="visual-frame"
|
| 725 |
+
width="100%"
|
| 726 |
+
height="600"
|
| 727 |
+
style="border:none; width:100%; min-height:600px;"
|
| 728 |
+
srcdoc="{escaped_content}">
|
| 729 |
+
</iframe>
|
| 730 |
+
</div>
|
| 731 |
+
"""
|
| 732 |
|
| 733 |
+
logging.info(f"The code produced for this graph placeholder:\n{placeholder_text}")
|
| 734 |
return htmloutput
|
| 735 |
|
| 736 |
def replace_graph_placeholders(report_html: str, context: str, initial_query: str, crumbs: str) -> str:
|
| 737 |
+
pattern = r"\[\[Graph Placeholder (\d+):(.*?)\]\]"
|
| 738 |
|
| 739 |
def placeholder_replacer(match):
|
| 740 |
placeholder_num = match.group(1)
|
|
|
|
| 743 |
|
| 744 |
try:
|
| 745 |
visual_html = generate_graph_snippet(instructions, context, initial_query, crumbs)
|
| 746 |
+
return f'<!-- Graph {placeholder_num} Start -->\n<div class="graph-container" style="margin:20px 0;">\n{visual_html}\n</div>\n<!-- Graph {placeholder_num} End -->'
|
|
|
|
| 747 |
except Exception as e:
|
| 748 |
logging.error(f"Graph {placeholder_num} failed: {str(e)}")
|
| 749 |
+
error_msg = f'<div class="error-message" style="color:red; border:1px solid red; padding:10px; margin:10px 0;">Error generating Graph {placeholder_num}: {str(e)}</div>'
|
| 750 |
+
return error_msg
|
| 751 |
|
| 752 |
return re.sub(pattern, placeholder_replacer, report_html, flags=re.DOTALL)
|
| 753 |
|