Accelernate commited on
Commit
2b3c568
·
verified ·
1 Parent(s): a656ee4

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +17 -7
app.py CHANGED
@@ -43,14 +43,24 @@ def get_protein_image(pdbview):
43
  pdbview.render()
44
  png = pdbview.pngImage()
45
 
46
- # Convert to IPython Image
47
- img = Image(png)
48
 
49
- # Save to BytesIO
50
- img_io = io.BytesIO()
51
- img.save(img_io, format='PNG')
52
- img_io.seek(0)
53
- png_bytes = img_io.getvalue()
 
 
 
 
 
 
 
 
 
 
54
 
55
  return base64.b64encode(png_bytes).decode('utf-8')
56
 
 
43
  pdbview.render()
44
  png = pdbview.pngImage()
45
 
46
+ print(f"Type of png: {type(png)}")
47
+ print(f"Dir of png: {dir(png)}")
48
 
49
+ if hasattr(png, 'shape'):
50
+ print(f"Shape of png: {png.shape}")
51
+
52
+ if hasattr(png, 'dtype'):
53
+ print(f"Dtype of png: {png.dtype}")
54
+
55
+ # Try to convert to bytes
56
+ if isinstance(png, (bytes, bytearray)):
57
+ png_bytes = png
58
+ elif hasattr(png, 'tobytes'):
59
+ png_bytes = png.tobytes()
60
+ elif hasattr(png, 'tostring'):
61
+ png_bytes = png.tostring()
62
+ else:
63
+ raise TypeError(f"Unable to convert {type(png)} to bytes")
64
 
65
  return base64.b64encode(png_bytes).decode('utf-8')
66