Accelernate commited on
Commit
a656ee4
·
verified ·
1 Parent(s): 4600a7a

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +10 -9
app.py CHANGED
@@ -12,6 +12,8 @@ from Bio.SeqRecord import SeqRecord
12
  import time
13
  import urllib.parse
14
  import base64
 
 
15
 
16
  urllib3.disable_warnings(urllib3.exceptions.InsecureRequestWarning)
17
 
@@ -40,16 +42,15 @@ def get_protein_image(pdbview):
40
  pdbview.zoom(0.8)
41
  pdbview.render()
42
  png = pdbview.pngImage()
43
- print(f"Type of png: {type(png)}")
44
- print(f"Dir of png: {dir(png)}")
45
 
46
- # Try to convert to bytes if possible
47
- if hasattr(png, 'tobytes'):
48
- png_bytes = png.tobytes()
49
- elif hasattr(png, 'tostring'):
50
- png_bytes = png.tostring()
51
- else:
52
- raise TypeError(f"Unable to convert {type(png)} to bytes")
 
53
 
54
  return base64.b64encode(png_bytes).decode('utf-8')
55
 
 
12
  import time
13
  import urllib.parse
14
  import base64
15
+ from IPython.display import Image
16
+ import io
17
 
18
  urllib3.disable_warnings(urllib3.exceptions.InsecureRequestWarning)
19
 
 
42
  pdbview.zoom(0.8)
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