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

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +7 -19
app.py CHANGED
@@ -41,28 +41,16 @@ def render_mol(pdb):
41
  def get_protein_image(pdbview):
42
  pdbview.zoom(0.8)
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
 
67
  def perform_blast_analysis(sequence):
68
  st.subheader('Protein Analysis')
 
41
  def get_protein_image(pdbview):
42
  pdbview.zoom(0.8)
43
  pdbview.render()
 
44
 
45
+ # Get the image data directly as a base64 encoded string
46
+ png_base64 = pdbview.js().png()
47
 
48
+ # The png_base64 should already be a base64 encoded string
49
+ # If it's not, we might need to encode it
50
+ if isinstance(png_base64, str):
51
+ return png_base64
 
 
 
 
 
 
 
 
 
52
  else:
53
+ return base64.b64encode(png_base64).decode('utf-8')
 
 
54
 
55
  def perform_blast_analysis(sequence):
56
  st.subheader('Protein Analysis')