Spaces:
Sleeping
Sleeping
Vaishnav14220 commited on
Commit ·
e125455
1
Parent(s): 146b4ff
Fix SVG generation in PDF by using temp files for svg2rlg
Browse files
app.py
CHANGED
|
@@ -78,15 +78,21 @@ def generate_all_reactions_pdf():
|
|
| 78 |
rxn = AllChem.ReactionFromSmarts(reaction_smiles)
|
| 79 |
if rxn:
|
| 80 |
svg_content = Draw.ReactionToImage(rxn, useSVG=True)
|
|
|
|
|
|
|
|
|
|
|
|
|
| 81 |
# Convert SVG to ReportLab drawing
|
| 82 |
-
drawing = svg2rlg(
|
| 83 |
if drawing:
|
| 84 |
# Scale the drawing to fit
|
| 85 |
drawing.width = 400
|
| 86 |
-
drawing.height =
|
| 87 |
-
drawing.scale(0.
|
| 88 |
story.append(drawing)
|
| 89 |
story.append(Spacer(1, 12))
|
|
|
|
|
|
|
| 90 |
except Exception as e:
|
| 91 |
# If SVG generation fails, just continue
|
| 92 |
pass
|
|
|
|
| 78 |
rxn = AllChem.ReactionFromSmarts(reaction_smiles)
|
| 79 |
if rxn:
|
| 80 |
svg_content = Draw.ReactionToImage(rxn, useSVG=True)
|
| 81 |
+
# Save SVG to temp file
|
| 82 |
+
svg_temp = tempfile.NamedTemporaryFile(delete=False, suffix='.svg')
|
| 83 |
+
svg_temp.write(svg_content.encode('utf-8'))
|
| 84 |
+
svg_temp.close()
|
| 85 |
# Convert SVG to ReportLab drawing
|
| 86 |
+
drawing = svg2rlg(svg_temp.name)
|
| 87 |
if drawing:
|
| 88 |
# Scale the drawing to fit
|
| 89 |
drawing.width = 400
|
| 90 |
+
drawing.height = 150
|
| 91 |
+
drawing.scale(0.8, 0.8)
|
| 92 |
story.append(drawing)
|
| 93 |
story.append(Spacer(1, 12))
|
| 94 |
+
# Clean up temp file
|
| 95 |
+
os.unlink(svg_temp.name)
|
| 96 |
except Exception as e:
|
| 97 |
# If SVG generation fails, just continue
|
| 98 |
pass
|