Spaces:
Running
Running
th Claude commited on
Commit ·
8d02c0c
1
Parent(s): 741463e
Fix SVG generation: read from file instead of return value
Browse files🐛 Critical fix:
- KerykeionChartSVG.makeSVG() saves to file, doesn't return content
- Create temp directory for SVG output
- Read generated SVG file content
- Return file content in HTTP response
✅ Now SVG generation works correctly!
References:
- https://github.com/g-battaglia/kerykeion
- https://www.kerykeion.net/pydocs/kerykeion.html
🤖 Generated with [Claude Code](https://claude.com/claude-code)
Co-Authored-By: Claude <noreply@anthropic.com>
app.py
CHANGED
|
@@ -177,10 +177,22 @@ async def generate_chart_svg(req: BirthRequest):
|
|
| 177 |
)
|
| 178 |
|
| 179 |
# Generate SVG chart (Kerykeion 4.x)
|
| 180 |
-
|
| 181 |
-
|
| 182 |
-
|
| 183 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 184 |
|
| 185 |
if not svg_content or len(svg_content) < 100:
|
| 186 |
raise HTTPException(status_code=500, detail="SVG generation returned empty content")
|
|
|
|
| 177 |
)
|
| 178 |
|
| 179 |
# Generate SVG chart (Kerykeion 4.x)
|
| 180 |
+
# makeSVG() saves to file, doesn't return content
|
| 181 |
+
import tempfile
|
| 182 |
+
from pathlib import Path
|
| 183 |
+
|
| 184 |
+
with tempfile.TemporaryDirectory() as tmpdir:
|
| 185 |
+
output_dir = Path(tmpdir)
|
| 186 |
+
chart = KerykeionChartSVG(subject, new_output_directory=str(output_dir))
|
| 187 |
+
chart.makeSVG()
|
| 188 |
+
|
| 189 |
+
# Find the generated SVG file
|
| 190 |
+
svg_files = list(output_dir.glob("*.svg"))
|
| 191 |
+
if not svg_files:
|
| 192 |
+
raise HTTPException(status_code=500, detail="No SVG file generated")
|
| 193 |
+
|
| 194 |
+
svg_file = svg_files[0]
|
| 195 |
+
svg_content = svg_file.read_text(encoding='utf-8')
|
| 196 |
|
| 197 |
if not svg_content or len(svg_content) < 100:
|
| 198 |
raise HTTPException(status_code=500, detail="SVG generation returned empty content")
|