Spaces:
Runtime error
Runtime error
Update reaction visualization to use PIL Image with exact ReactionToImage parameters
Browse files
app.py
CHANGED
|
@@ -230,10 +230,18 @@ def reaction_smiles_to_svg(reaction_smiles: str) -> str:
|
|
| 230 |
for mol in product_mols:
|
| 231 |
reaction.AddProductTemplate(mol)
|
| 232 |
|
| 233 |
-
# Draw the reaction as
|
| 234 |
-
|
| 235 |
|
| 236 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 237 |
|
| 238 |
except gr.Error:
|
| 239 |
raise
|
|
|
|
| 230 |
for mol in product_mols:
|
| 231 |
reaction.AddProductTemplate(mol)
|
| 232 |
|
| 233 |
+
# Draw the reaction as image
|
| 234 |
+
image = Draw.ReactionToImage(reaction, subImgSize=(200, 200), useSVG=False, drawOptions=None, returnPNG=False)
|
| 235 |
|
| 236 |
+
# Convert PIL image to base64 for HTML display
|
| 237 |
+
import io
|
| 238 |
+
import base64
|
| 239 |
+
buffer = io.BytesIO()
|
| 240 |
+
image.save(buffer, format='PNG')
|
| 241 |
+
img_str = base64.b64encode(buffer.getvalue()).decode()
|
| 242 |
+
|
| 243 |
+
# Return as HTML img tag
|
| 244 |
+
return f'<img src="data:image/png;base64,{img_str}" alt="Reaction" style="max-width:100%; height:auto;">'
|
| 245 |
|
| 246 |
except gr.Error:
|
| 247 |
raise
|