Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
|
@@ -31,8 +31,7 @@ MAX_MESSAGE_LENGTH = 1048576
|
|
| 31 |
|
| 32 |
def generate_visual_snippet(placeholder_text: str, context: str, initial_query: str, crumbs: str) -> str:
|
| 33 |
prompt = (f"""
|
| 34 |
-
Generate a
|
| 35 |
-
The code should display a simple but effective and elegant visualization based on the following requirements:
|
| 36 |
{placeholder_text}
|
| 37 |
|
| 38 |
It will be integrated in a broader report (in html) about:
|
|
@@ -46,276 +45,112 @@ Keep in mind the:
|
|
| 46 |
{crumbs}
|
| 47 |
|
| 48 |
// Requirements
|
| 49 |
-
- use
|
| 50 |
- White background (#ffffff)
|
| 51 |
- overall dimension capped at 500px x 500px
|
| 52 |
-
- Font size minimum 12px for readability in PDF
|
| 53 |
-
- Use high-contrast colors (no dark backgrounds)
|
| 54 |
-
- use a title on the top <h3> aligned on the left
|
| 55 |
- no introduction, conclusions or code fences -> Output the result directly
|
| 56 |
|
| 57 |
// Important
|
| 58 |
-
- Make the visuals content rich, there's no point having a visual if its content
|
| 59 |
- It has to convey some relevant insights.
|
| 60 |
- Take a deep breath, think step by step and think it well.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 61 |
""")
|
| 62 |
|
| 63 |
result = openai_call(prompt, model="o3-mini", max_tokens_param=10000)
|
| 64 |
result = result.strip().strip("```").strip()
|
| 65 |
-
logging.info(f"The code produced for this visual placeholder:\n{placeholder_text}\n\n {result}\n\n")
|
| 66 |
-
return result
|
| 67 |
-
|
| 68 |
-
def generate_visual_snippet_tofix(placeholder_text: str, context: str, initial_query: str, crumbs: str) -> str:
|
| 69 |
-
prompt = (f"""
|
| 70 |
-
Generate a complete, self-contained HTML code snippet between <div> tags that includes inline CSS and JavaScript.
|
| 71 |
-
The code should display a simple but effective and elegant visualization based on the following requirements:
|
| 72 |
-
{placeholder_text}
|
| 73 |
-
It will be integrated in a broader report (in html) about:
|
| 74 |
-
{initial_query}
|
| 75 |
-
|
| 76 |
-
// Sources:
|
| 77 |
-
Keep in mind the:
|
| 78 |
-
- context:
|
| 79 |
-
{context}
|
| 80 |
-
- the knowledge inputs
|
| 81 |
-
{crumbs}
|
| 82 |
-
|
| 83 |
-
// Different types of visuals
|
| 84 |
-
- There can be 2 types of visuals:
|
| 85 |
-
o Simple management or ideation diagrams that can be generated in html directly (ex: ganntt chart or five forces, ... )
|
| 86 |
-
o Complex diagrams requiring a library (ex: )
|
| 87 |
-
Note: For advanced ones, use only the example below
|
| 88 |
-
|
| 89 |
-
// Requirements
|
| 90 |
-
- White background (#ffffff)
|
| 91 |
-
- overall dimension capped at 500px x 500px
|
| 92 |
-
- Include explicit width/height attributes in SVG tags (500px)
|
| 93 |
-
- Font size minimum 12px for readability in PDF
|
| 94 |
-
- Use high-contrast colors (no dark backgrounds)
|
| 95 |
-
- use a title on the top <h3> aligned on the left
|
| 96 |
-
- no introduction, conclusions, code fences -> Output the result directly
|
| 97 |
|
| 98 |
-
|
| 99 |
-
|
| 100 |
-
|
| 101 |
-
|
| 102 |
-
|
| 103 |
-
|
| 104 |
-
|
| 105 |
-
|
| 106 |
-
|
| 107 |
-
|
| 108 |
-
|
| 109 |
-
|
| 110 |
-
|
| 111 |
-
|
| 112 |
-
|
| 113 |
-
|
| 114 |
-
|
| 115 |
-
|
| 116 |
-
|
| 117 |
-
|
| 118 |
-
|
| 119 |
-
|
| 120 |
-
|
| 121 |
-
|
| 122 |
-
|
| 123 |
-
|
| 124 |
-
|
| 125 |
-
<
|
| 126 |
-
|
| 127 |
-
|
| 128 |
-
<
|
| 129 |
-
|
| 130 |
-
|
| 131 |
-
<g transform="rotate(72,250,250)">
|
| 132 |
-
<circle class="force-circle" cx="250" cy="100" r="40" data-force="suppliers"/>
|
| 133 |
-
<text class="force-text" x="250" y="90" text-anchor="middle">Supplier Power</text>
|
| 134 |
-
<text class="force-value" x="250" y="110" text-anchor="middle">65%</text>
|
| 135 |
-
<line class="connector" x1="250" y1="140" x2="250" y2="200"/>
|
| 136 |
-
</g>
|
| 137 |
-
|
| 138 |
-
<g transform="rotate(144,250,250)">
|
| 139 |
-
<circle class="force-circle" cx="250" cy="100" r="40" data-force="buyers"/>
|
| 140 |
-
<text class="force-text" x="250" y="90" text-anchor="middle">Buyer Power</text>
|
| 141 |
-
<text class="force-value" x="250" y="110" text-anchor="middle">68%</text>
|
| 142 |
-
<line class="connector" x1="250" y1="140" x2="250" y2="200"/>
|
| 143 |
-
</g>
|
| 144 |
-
|
| 145 |
-
<g transform="rotate(216,250,250)">
|
| 146 |
-
<circle class="force-circle" cx="250" cy="100" r="40" data-force="substitutes"/>
|
| 147 |
-
<text class="force-text" x="250" y="90" text-anchor="middle">Substitutes</text>
|
| 148 |
-
<text class="force-value" x="250" y="110" text-anchor="middle">85%</text>
|
| 149 |
-
<line class="connector" x1="250" y1="140" x2="250" y2="200"/>
|
| 150 |
-
</g>
|
| 151 |
-
|
| 152 |
-
<g transform="rotate(288,250,250)">
|
| 153 |
-
<circle class="force-circle" cx="250" cy="100" r="40" data-force="new_entrants"/>
|
| 154 |
-
<text class="force-text" x="250" y="90" text-anchor="middle">New Entrants</text>
|
| 155 |
-
<text class="force-value" x="250" y="110" text-anchor="middle">58%</text>
|
| 156 |
-
<line class="connector" x1="250" y1="140" x2="250" y2="200"/>
|
| 157 |
-
</g>
|
| 158 |
-
|
| 159 |
-
<!-- Interactive Tooltip -->
|
| 160 |
-
<foreignObject x="0" y="400" width="500" height="100">
|
| 161 |
-
<div xmlns="http://www.w3.org/1999/xhtml" class="tooltip"
|
| 162 |
-
style="text-align:center; font-size:12px; color:#666; padding:10px">
|
| 163 |
-
Hover over any force for details
|
| 164 |
</div>
|
| 165 |
-
</
|
| 166 |
-
</
|
| 167 |
-
|
| 168 |
-
<script>
|
| 169 |
-
const forceData = {{
|
| 170 |
-
rivalry: "High competition from 10+ major brands. Price wars common (-15% margin impact)",
|
| 171 |
-
suppliers: "Limited dairy suppliers (3 major players control 80% market)",
|
| 172 |
-
buyers: "Consumers show high price sensitivity (68% would switch brands for 10% discount)",
|
| 173 |
-
substitutes: "Strong alternatives: frozen yogurt (+25% growth), plant-based options",
|
| 174 |
-
new_entrants: "Moderate barriers: $2M+ minimum investment, established distribution needed"
|
| 175 |
-
}};
|
| 176 |
-
|
| 177 |
-
document.querySelectorAll('.force-circle').forEach(circle => {{
|
| 178 |
-
circle.addEventListener('mouseover', function() {{
|
| 179 |
-
const force = this.dataset.force;
|
| 180 |
-
document.querySelector('.tooltip').innerHTML =
|
| 181 |
-
`<strong>${{this.parentNode.querySelector('text').textContent}}</strong><br>
|
| 182 |
-
${{forceData[force]}}`;
|
| 183 |
-
}});
|
| 184 |
-
}});
|
| 185 |
-
</script>
|
| 186 |
-
</div>
|
| 187 |
-
|
| 188 |
-
// Example of complex visual (This is a reference - use a similar structure for any other visual):
|
| 189 |
-
<!-- Visual Placeholder 2 -->
|
| 190 |
-
<div class=\"visual-placeholder\">
|
| 191 |
-
<!-- Visual 2 Start -->
|
| 192 |
-
<!DOCTYPE html>
|
| 193 |
-
<html lang=\"en\">
|
| 194 |
-
<head>
|
| 195 |
-
<meta charset=\"UTF-8\" />
|
| 196 |
-
<title>AI Advancement Timeline: 2021-2025</title>
|
| 197 |
-
<style>
|
| 198 |
-
body {{
|
| 199 |
-
background-color: #ffffff;
|
| 200 |
-
font-family: Arial, sans-serif;
|
| 201 |
-
margin: 20px;
|
| 202 |
-
}}
|
| 203 |
-
h1 {{
|
| 204 |
-
text-align: left;
|
| 205 |
-
font-size: 20px;
|
| 206 |
-
}}
|
| 207 |
-
.svg-text {{
|
| 208 |
-
font-size: 12px;
|
| 209 |
-
fill: #000000;
|
| 210 |
-
}}
|
| 211 |
-
.event-circle {{
|
| 212 |
-
cursor: pointer;
|
| 213 |
-
stroke-width: 2;
|
| 214 |
-
}}
|
| 215 |
-
</style>
|
| 216 |
-
</head>
|
| 217 |
-
<body>
|
| 218 |
-
<h1>AI Advancements & Disruptions Timeline (2021-2025)</h1>
|
| 219 |
-
<svg width=\"500\" height=\"500\" xmlns=\"http://www.w3.org/2000/svg\" role=\"img\" aria-labelledby=\"titleID descID\">
|
| 220 |
-
<title id=\"titleID\">Timeline of Expected AI Disruptions and Milestones</title>
|
| 221 |
-
<desc id=\"descID\">
|
| 222 |
-
A horizontal timeline from 2021 to 2025 with event markers in blue and orange highlighting key technologies and breakthroughs.
|
| 223 |
-
</desc>
|
| 224 |
-
<!-- Draw horizontal timeline -->
|
| 225 |
-
<line x1=\"50\" y1=\"250\" x2=\"450\" y2=\"250\" stroke=\"#000000\" stroke-width=\"2\" />
|
| 226 |
-
|
| 227 |
-
<!-- 2021: Deepseek: Speed of Deployment (Disruption, blue) -->
|
| 228 |
-
<g id=\"event2021\">
|
| 229 |
-
<!-- Marker above the line -->
|
| 230 |
-
<circle cx=\"50\" cy=\"200\" r=\"10\" fill=\"#1f77b4\" class=\"event-circle\" stroke=\"#1f77b4\" />
|
| 231 |
-
<!-- Line connector -->
|
| 232 |
-
<line x1=\"50\" y1=\"210\" x2=\"50\" y2=\"250\" stroke=\"#1f77b4\" stroke-dasharray=\"4\" stroke-width=\"1\"/>
|
| 233 |
-
<!-- Text label -->
|
| 234 |
-
<text x=\"50\" y=\"185\" text-anchor=\"middle\" class=\"svg-text\">2021</text>
|
| 235 |
-
<text x=\"50\" y=\"170\" text-anchor=\"middle\" class=\"svg-text\">Deepseek: Deployment Speed</text>
|
| 236 |
-
</g>
|
| 237 |
-
|
| 238 |
-
<!-- 2022: Mobile & IoT Adoption (Breakthrough, orange) -->
|
| 239 |
-
<g id=\"event2022\">
|
| 240 |
-
<!-- Marker below the line -->
|
| 241 |
-
<circle cx=\"150\" cy=\"300\" r=\"10\" fill=\"#ff7f0e\" class=\"event-circle\" stroke=\"#ff7f0e\" />
|
| 242 |
-
<!-- Line connector -->
|
| 243 |
-
<line x1=\"150\" y1=\"250\" x2=\"150\" y2=\"290\" stroke=\"#ff7f0e\" stroke-dasharray=\"4\" stroke-width=\"1\"/>
|
| 244 |
-
<!-- Text label -->
|
| 245 |
-
<text x=\"150\" y=\"320\" text-anchor=\"middle\" class=\"svg-text\">2022</text>
|
| 246 |
-
<text x=\"150\" y=\"335\" text-anchor=\"middle\" class=\"svg-text\">Mobile & IoT Adoption</text>
|
| 247 |
-
</g>
|
| 248 |
-
|
| 249 |
-
<!-- 2023: Infinite Context Windows (Disruption, blue) -->
|
| 250 |
-
<g id=\"event2023\">
|
| 251 |
-
<!-- Marker above the line -->
|
| 252 |
-
<circle cx=\"250\" cy=\"200\" r=\"10\" fill=\"#1f77b4\" class=\"event-circle\" stroke=\"#1f77b4\" />
|
| 253 |
-
<!-- Line connector -->
|
| 254 |
-
<line x1=\"250\" y1=\"210\" x2=\"250\" y2=\"250\" stroke=\"#1f77b4\" stroke-dasharray=\"4\" stroke-width=\"1\"/>
|
| 255 |
-
<!-- Text label -->
|
| 256 |
-
<text x=\"250\" y=\"185\" text-anchor=\"middle\" class=\"svg-text\">2023</text>
|
| 257 |
-
<text x=\"250\" y=\"170\" text-anchor=\"middle\" class=\"svg-text\">Infinite Context Windows</text>
|
| 258 |
-
<text x=\"250\" y=\"155\" text-anchor=\"middle\" class=\"svg-text\">NLP Use Cases</text>
|
| 259 |
-
</g>
|
| 260 |
-
|
| 261 |
-
<!-- 2024: TTT Paradigm & New Architectures; Agentic Architecture Breakthrough (Breakthrough, orange) -->
|
| 262 |
-
<g id=\"event2024\">
|
| 263 |
-
<!-- Marker below the line -->
|
| 264 |
-
<circle cx=\"350\" cy=\"300\" r=\"10\" fill=\"#ff7f0e\" class=\"event-circle\" stroke=\"#ff7f0e\" />
|
| 265 |
-
<!-- Line connector -->
|
| 266 |
-
<line x1=\"350\" y1=\"250\" x2=\"350\" y2=\"290\" stroke=\"#ff7f0e\" stroke-dasharray=\"4\" stroke-width=\"1\"/>
|
| 267 |
-
<!-- Text label -->
|
| 268 |
-
<text x=\"350\" y=\"320\" text-anchor=\"middle\" class=\"svg-text\">2024</text>
|
| 269 |
-
<text x=\"350\" y=\"335\" text-anchor=\"middle\" class=\"svg-text\">TTT & New Architecture</text>
|
| 270 |
-
<text x=\"350\" y=\"350\" text-anchor=\"middle\" class=\"svg-text\">Agentic Breakthrough</text>
|
| 271 |
-
</g>
|
| 272 |
-
|
| 273 |
-
<!-- 2025: Convergence of Technologies (Disruption, blue) -->
|
| 274 |
-
<g id=\"event2025\">
|
| 275 |
-
<!-- Marker above the line -->
|
| 276 |
-
<circle cx=\"450\" cy=\"200\" r=\"10\" fill=\"#1f77b4\" class=\"event-circle\" stroke=\"#1f77b4\" />
|
| 277 |
-
<!-- Line connector -->
|
| 278 |
-
<line x1=\"450\" y1=\"210\" x2=\"450\" y2=\"250\" stroke=\"#1f77b4\" stroke-dasharray=\"4\" stroke-width=\"1\"/>
|
| 279 |
-
<!-- Text label -->
|
| 280 |
-
<text x=\"450\" y=\"185\" text-anchor=\"middle\" class=\"svg-text\">2025</text>
|
| 281 |
-
<text x=\"450\" y=\"170\" text-anchor=\"middle\" class=\"svg-text\">Convergence: VJEPA,</text>
|
| 282 |
-
<text x=\"450\" y=\"155\" text-anchor=\"middle\" class=\"svg-text\">Synthetic Data & Reasoning</text>
|
| 283 |
-
</g>
|
| 284 |
-
</svg>
|
| 285 |
-
|
| 286 |
-
<script>
|
| 287 |
-
// JavaScript: add click event listeners to each event marker to show more details
|
| 288 |
-
document.getElementById(\"event2021\").addEventListener(\"click\", function(evt) {{
|
| 289 |
-
alert(\"2021: Deepseek disruption accelerates deployment speeds, lowering barriers and affecting employment dynamics.\");
|
| 290 |
-
}});
|
| 291 |
-
|
| 292 |
-
document.getElementById(\"event2022\").addEventListener(\"click\", function(evt) {{
|
| 293 |
-
alert(\"2022: Rapid adoption in Mobile & IoT sectors enhances portability and connectivity, driving operational efficiency.\");
|
| 294 |
-
}});
|
| 295 |
-
|
| 296 |
-
document.getElementById(\"event2023\").addEventListener(\"click\", function(evt) {{
|
| 297 |
-
alert(\"2023: Infinite Context Windows usher in new use cases for NLP, expanding the scope of language model applications.\");
|
| 298 |
-
}});
|
| 299 |
-
|
| 300 |
-
document.getElementById(\"event2024\").addEventListener(\"click\", function(evt) {{
|
| 301 |
-
alert(\"2024: TTT paradigms and new architectural designs, including agentic architectures, promise transformative methodological shifts in AI.\");
|
| 302 |
-
}});
|
| 303 |
-
|
| 304 |
-
document.getElementById(\"event2025\").addEventListener(\"click\", function(evt) {{
|
| 305 |
-
alert(\"2025: A convergence of innovations \u2013 VJEPA integration, synthetic data, and emerging reasoning models \u2013 reshapes the AI landscape.\");
|
| 306 |
-
}});
|
| 307 |
-
</script>
|
| 308 |
-
</body>
|
| 309 |
-
</html>
|
| 310 |
-
<!-- Visual 2 End -->
|
| 311 |
-
</div>
|
| 312 |
-
|
| 313 |
-
""")
|
| 314 |
|
| 315 |
-
|
| 316 |
-
|
| 317 |
-
logging.info(f"The code produced for this visual placeholder:\n{placeholder_text}\n\n {result}\n\n")
|
| 318 |
-
return result
|
| 319 |
|
| 320 |
def replace_visual_placeholders(report_html: str, context: str, initial_query: str, crumbs: str) -> str:
|
| 321 |
pattern = r"\[\[Visual Placeholder (\d+):(.*?)\]\]" # Capture placeholder number
|
|
@@ -624,7 +459,7 @@ The report should be very detailed and lengthy — approximately the equivalent
|
|
| 624 |
- Text Alignment has to be to the left, including for the titles
|
| 625 |
|
| 626 |
// Visual placeholders
|
| 627 |
-
- Since the generation of visuals (excluding tables) like graph or charts cannot be done through text, create special visual placeholders in
|
| 628 |
[[Visual Placeholder n:
|
| 629 |
- Purpose of this visual is:...
|
| 630 |
- Relevant data to generate it:...
|
|
@@ -633,6 +468,7 @@ The report should be very detailed and lengthy — approximately the equivalent
|
|
| 633 |
with n as the reference number
|
| 634 |
Important: after [[ put "Visual Placeholder n:" explicitly (with n as the ref number of the focus box created). This will be used in a regex
|
| 635 |
|
|
|
|
| 636 |
- do not make reference in the report to "visual placeholders" just mention visuals.
|
| 637 |
- in the placeholder, no need to add the references to the source, but make sure ALL of the data points required has a source from the learning and reference material hereafter
|
| 638 |
- these placeholders text should contain:
|
|
|
|
| 31 |
|
| 32 |
def generate_visual_snippet(placeholder_text: str, context: str, initial_query: str, crumbs: str) -> str:
|
| 33 |
prompt = (f"""
|
| 34 |
+
Generate a mermaid code displaying a simple but effective and elegant visualization based on the following requirements:
|
|
|
|
| 35 |
{placeholder_text}
|
| 36 |
|
| 37 |
It will be integrated in a broader report (in html) about:
|
|
|
|
| 45 |
{crumbs}
|
| 46 |
|
| 47 |
// Requirements
|
| 48 |
+
- use standard mermaid visual rendering (ex: flowchart, sequence, gantt, pie, mindmap)
|
| 49 |
- White background (#ffffff)
|
| 50 |
- overall dimension capped at 500px x 500px
|
|
|
|
|
|
|
|
|
|
| 51 |
- no introduction, conclusions or code fences -> Output the result directly
|
| 52 |
|
| 53 |
// Important
|
| 54 |
+
- Make the visuals content rich, there's no point having a visual if its content has no real value.
|
| 55 |
- It has to convey some relevant insights.
|
| 56 |
- Take a deep breath, think step by step and think it well.
|
| 57 |
+
|
| 58 |
+
// Examples
|
| 59 |
+
-- flowchart --
|
| 60 |
+
flowchart TD
|
| 61 |
+
A[Christmas] -->|Get money| B(Go shopping)
|
| 62 |
+
B --> C{Let me think}
|
| 63 |
+
C -->|One| D[Laptop]
|
| 64 |
+
C -->|Two| E[iPhone]
|
| 65 |
+
C -->|Three| F[fa:fa-car Car]
|
| 66 |
+
|
| 67 |
+
-- sequence --
|
| 68 |
+
sequenceDiagram
|
| 69 |
+
Alice->>+John: Hello John, how are you?
|
| 70 |
+
Alice->>+John: John, can you hear me?
|
| 71 |
+
John-->>-Alice: Hi Alice, I can hear you!
|
| 72 |
+
John-->>-Alice: I feel great!
|
| 73 |
+
|
| 74 |
+
-- gantt --
|
| 75 |
+
gantt
|
| 76 |
+
title A Gantt Diagram
|
| 77 |
+
dateFormat YYYY-MM-DD
|
| 78 |
+
section Section
|
| 79 |
+
A task :a1, 2014-01-01, 30d
|
| 80 |
+
Another task :after a1 , 20d
|
| 81 |
+
section Another
|
| 82 |
+
Task in sec :2014-01-12 , 12d
|
| 83 |
+
another task : 24d
|
| 84 |
+
|
| 85 |
+
-- pie --
|
| 86 |
+
pie title Pets adopted by volunteers
|
| 87 |
+
"Dogs" : 386
|
| 88 |
+
"Cats" : 85
|
| 89 |
+
"Rats" : 15
|
| 90 |
+
|
| 91 |
+
-- mindmap --
|
| 92 |
+
mindmap
|
| 93 |
+
root((mindmap))
|
| 94 |
+
Origins
|
| 95 |
+
Long history
|
| 96 |
+
::icon(fa fa-book)
|
| 97 |
+
Popularisation
|
| 98 |
+
British popular psychology author Tony Buzan
|
| 99 |
+
Research
|
| 100 |
+
On effectivness<br/>and features
|
| 101 |
+
On Automatic creation
|
| 102 |
+
Uses
|
| 103 |
+
Creative techniques
|
| 104 |
+
Strategic planning
|
| 105 |
+
Argument mapping
|
| 106 |
+
Tools
|
| 107 |
+
Pen and paper
|
| 108 |
+
Mermaid
|
| 109 |
+
|
| 110 |
""")
|
| 111 |
|
| 112 |
result = openai_call(prompt, model="o3-mini", max_tokens_param=10000)
|
| 113 |
result = result.strip().strip("```").strip()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 114 |
|
| 115 |
+
htmloutput = f""" <iframe srcdoc='
|
| 116 |
+
<!DOCTYPE html>
|
| 117 |
+
<html>
|
| 118 |
+
<head>
|
| 119 |
+
<script type="module">
|
| 120 |
+
import mermaid from "https://cdn.jsdelivr.net/npm/mermaid@10/dist/mermaid.esm.min.mjs";
|
| 121 |
+
import zenuml from "https://cdn.jsdelivr.net/npm/@mermaid-js/mermaid-zenuml@0.1.0/dist/mermaid-zenuml.esm.min.mjs";
|
| 122 |
+
|
| 123 |
+
async function initialize() {{
|
| 124 |
+
await mermaid.registerExternalDiagrams([zenuml]);
|
| 125 |
+
mermaid.initialize({{
|
| 126 |
+
startOnLoad: true,
|
| 127 |
+
securityLevel: "loose",
|
| 128 |
+
theme: "default"
|
| 129 |
+
}});
|
| 130 |
+
}}
|
| 131 |
+
|
| 132 |
+
initialize();
|
| 133 |
+
</script>
|
| 134 |
+
<style>
|
| 135 |
+
.mermaid {{
|
| 136 |
+
background-color: white;
|
| 137 |
+
padding: 10px;
|
| 138 |
+
border-radius: 5px;
|
| 139 |
+
max-width: 100%;
|
| 140 |
+
margin: 0 auto;
|
| 141 |
+
}}
|
| 142 |
+
</style>
|
| 143 |
+
</head>
|
| 144 |
+
<body>
|
| 145 |
+
<div class="mermaid">
|
| 146 |
+
{result}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 147 |
</div>
|
| 148 |
+
</body>
|
| 149 |
+
</html>' width="100%" height="800px" style="border:none;"></iframe>
|
| 150 |
+
"""
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 151 |
|
| 152 |
+
logging.info(f"The code produced for this visual placeholder:\n{placeholder_text}\n\n {htmloutput}\n\n")
|
| 153 |
+
return htmloutput
|
|
|
|
|
|
|
| 154 |
|
| 155 |
def replace_visual_placeholders(report_html: str, context: str, initial_query: str, crumbs: str) -> str:
|
| 156 |
pattern = r"\[\[Visual Placeholder (\d+):(.*?)\]\]" # Capture placeholder number
|
|
|
|
| 459 |
- Text Alignment has to be to the left, including for the titles
|
| 460 |
|
| 461 |
// Visual placeholders
|
| 462 |
+
- Since the generation of visuals (excluding tables) like graph or charts cannot be done through text, create special visual placeholders that will be rendered in mermaid afterwards based on your guidance:
|
| 463 |
[[Visual Placeholder n:
|
| 464 |
- Purpose of this visual is:...
|
| 465 |
- Relevant data to generate it:...
|
|
|
|
| 468 |
with n as the reference number
|
| 469 |
Important: after [[ put "Visual Placeholder n:" explicitly (with n as the ref number of the focus box created). This will be used in a regex
|
| 470 |
|
| 471 |
+
- the only types of mermaid diagram that can be generated are: flowchart, sequence, gantt, pie, mindmap // Take this into consideration when providing the instructions for the diagram
|
| 472 |
- do not make reference in the report to "visual placeholders" just mention visuals.
|
| 473 |
- in the placeholder, no need to add the references to the source, but make sure ALL of the data points required has a source from the learning and reference material hereafter
|
| 474 |
- these placeholders text should contain:
|