Nanny7 commited on
Commit
63c87ea
·
1 Parent(s): eaef0cd

Update reaction visualization to use PIL Image with exact ReactionToImage parameters

Browse files
Files changed (1) hide show
  1. app.py +11 -3
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 SVG
234
- svg = Draw.ReactionToImage(reaction, subImgSize=(200, 200), useSVG=True, drawOptions=None, returnPNG=False)
235
 
236
- return svg
 
 
 
 
 
 
 
 
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