Spaces:
Running
Running
Commit ·
2732803
1
Parent(s): be3f607
Added errors to output the raw mermaid code
Browse files
app.py
CHANGED
|
@@ -198,17 +198,27 @@ index_html = """
|
|
| 198 |
submitBtn.textContent = "Generating...";
|
| 199 |
targetDiv.innerHTML = "Generating diagram...";
|
| 200 |
|
|
|
|
| 201 |
try {
|
| 202 |
// Call the @app.api function registered in python (name + param must match)
|
| 203 |
const result = await client.predict("/generate_flowchart", { src_code: codeValue });
|
| 204 |
-
|
| 205 |
|
| 206 |
// Inject the raw string into a clean layout block and re-trigger parsing
|
| 207 |
targetDiv.innerHTML = `<pre class="mermaid">${mermaidSyntax}</pre>`;
|
| 208 |
await mermaid.run();
|
| 209 |
|
| 210 |
} catch (error) {
|
| 211 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 212 |
} finally {
|
| 213 |
submitBtn.disabled = false;
|
| 214 |
submitBtn.textContent = "Generate Flowchart";
|
|
|
|
| 198 |
submitBtn.textContent = "Generating...";
|
| 199 |
targetDiv.innerHTML = "Generating diagram...";
|
| 200 |
|
| 201 |
+
let mermaidSyntax = "";
|
| 202 |
try {
|
| 203 |
// Call the @app.api function registered in python (name + param must match)
|
| 204 |
const result = await client.predict("/generate_flowchart", { src_code: codeValue });
|
| 205 |
+
mermaidSyntax = result.data[0];
|
| 206 |
|
| 207 |
// Inject the raw string into a clean layout block and re-trigger parsing
|
| 208 |
targetDiv.innerHTML = `<pre class="mermaid">${mermaidSyntax}</pre>`;
|
| 209 |
await mermaid.run();
|
| 210 |
|
| 211 |
} catch (error) {
|
| 212 |
+
// On failure show the error AND the exact raw Mermaid we tried to render,
|
| 213 |
+
// so a parse error can be diagnosed from the real output. textContent is
|
| 214 |
+
// used for the raw string so newlines/special chars can't break the page.
|
| 215 |
+
targetDiv.innerHTML = "<p style='color:red;'>Error during generation: " + error.message + "</p><p style='color:#111;font-weight:bold;text-align:left;'>Raw Mermaid output:</p>";
|
| 216 |
+
const dbg = document.createElement("pre");
|
| 217 |
+
dbg.style.color = "#111";
|
| 218 |
+
dbg.style.whiteSpace = "pre-wrap";
|
| 219 |
+
dbg.style.textAlign = "left";
|
| 220 |
+
dbg.textContent = mermaidSyntax;
|
| 221 |
+
targetDiv.appendChild(dbg);
|
| 222 |
} finally {
|
| 223 |
submitBtn.disabled = false;
|
| 224 |
submitBtn.textContent = "Generate Flowchart";
|