paulbricman commited on
Commit
72e2c8b
1 Parent(s): 1ef11ef

fix: backend bug with alpha images

Browse files

backend/util.py CHANGED
@@ -217,9 +217,17 @@ def encode(modality, content, text_encoder, text_image_encoder):
217
  'text_image': [round(e, 5) for e in text_image_encoder.encode(content).tolist()]
218
  }
219
  elif modality == 'image':
 
 
 
 
 
 
 
 
220
  return {
221
  'text_image_model': 'clip-ViT-B-32',
222
- 'text_image': [round(e, 5) for e in text_image_encoder.encode(Image.open(io.BytesIO(content))).tolist()]
223
  }
224
  else:
225
  raise Exception('Can\'t encode content of modality "' + modality + '"')
217
  'text_image': [round(e, 5) for e in text_image_encoder.encode(content).tolist()]
218
  }
219
  elif modality == 'image':
220
+ content = Image.open(io.BytesIO(content))
221
+ img_io = io.BytesIO()
222
+ content = content.convert('RGB')
223
+ content.save(img_io, 'jpeg')
224
+ img_io.seek(0)
225
+ content = img_io.read()
226
+ content = Image.open(img_io)
227
+
228
  return {
229
  'text_image_model': 'clip-ViT-B-32',
230
+ 'text_image': [round(e, 5) for e in text_image_encoder.encode(content).tolist()]
231
  }
232
  else:
233
  raise Exception('Can\'t encode content of modality "' + modality + '"')
frontend/components/__pycache__/inspector.cpython-38.pyc CHANGED
Binary files a/frontend/components/__pycache__/inspector.cpython-38.pyc and b/frontend/components/__pycache__/inspector.cpython-38.pyc differ
frontend/components/inspector.py CHANGED
@@ -71,13 +71,13 @@ def paint():
71
  query = st.session_state['navigator_input']
72
  if isinstance(query, UploadedFile):
73
  query = Image.open(io.BytesIO(query.getvalue()))
74
-
75
  img_io = io.BytesIO()
76
  query = query.convert('RGB')
77
  query.save(img_io, 'jpeg')
78
  img_io.seek(0)
79
  query = img_io.read()
80
-
81
  requests.post(custodian_microverse[0]['url'] + '/save', data={
82
  'token': custodian_microverse[0]['token']}, files={
83
  'query': query
@@ -94,13 +94,13 @@ def paint():
94
  query = st.session_state['navigator_input']
95
  if isinstance(query, UploadedFile):
96
  query = Image.open(io.BytesIO(query.getvalue()))
97
-
98
  img_io = io.BytesIO()
99
  query = query.convert('RGB')
100
  query.save(img_io, 'jpeg')
101
  img_io.seek(0)
102
  query = img_io.read()
103
-
104
  response = requests.post(custodian_microverse[0]['url'] + '/microverse/create', data={
105
  'token': custodian_microverse[0]['token']}, files={
106
  'query': query
71
  query = st.session_state['navigator_input']
72
  if isinstance(query, UploadedFile):
73
  query = Image.open(io.BytesIO(query.getvalue()))
74
+
75
  img_io = io.BytesIO()
76
  query = query.convert('RGB')
77
  query.save(img_io, 'jpeg')
78
  img_io.seek(0)
79
  query = img_io.read()
80
+
81
  requests.post(custodian_microverse[0]['url'] + '/save', data={
82
  'token': custodian_microverse[0]['token']}, files={
83
  'query': query
94
  query = st.session_state['navigator_input']
95
  if isinstance(query, UploadedFile):
96
  query = Image.open(io.BytesIO(query.getvalue()))
97
+
98
  img_io = io.BytesIO()
99
  query = query.convert('RGB')
100
  query.save(img_io, 'jpeg')
101
  img_io.seek(0)
102
  query = img_io.read()
103
+
104
  response = requests.post(custodian_microverse[0]['url'] + '/microverse/create', data={
105
  'token': custodian_microverse[0]['token']}, files={
106
  'query': query
util.py → scripts/util.py RENAMED
File without changes