Spaces:
Sleeping
Sleeping
katerinavr commited on
update the code
Browse files
app.py
CHANGED
|
@@ -13,19 +13,11 @@ import os
|
|
| 13 |
from PIL import Image
|
| 14 |
import io
|
| 15 |
|
| 16 |
-
# Convert byte strings to images
|
| 17 |
def convert_to_image(byte_data):
|
|
|
|
|
|
|
| 18 |
return Image.open(io.BytesIO(byte_data))
|
| 19 |
|
| 20 |
-
|
| 21 |
-
# # Load the token from the environment variable
|
| 22 |
-
# hf_token = os.getenv('HF_AUTH_TOKEN')
|
| 23 |
-
# if hf_token:
|
| 24 |
-
# HfFolder.save_token(hf_token)
|
| 25 |
-
# else:
|
| 26 |
-
# raise ValueError("HF_AUTH_TOKEN environment variable is not set")
|
| 27 |
-
|
| 28 |
-
|
| 29 |
# Load the model and dataset
|
| 30 |
model = SentenceTransformer('clip-ViT-B-32')
|
| 31 |
ds_with_embeddings = load_dataset("kvriza8/clip_microscopy_image_text_embeddings")
|
|
@@ -34,11 +26,6 @@ ds_with_embeddings = load_dataset("kvriza8/clip_microscopy_image_text_embeddings
|
|
| 34 |
# Initialize FAISS index once
|
| 35 |
ds_with_embeddings['train'].add_faiss_index(column='img_embeddings')
|
| 36 |
|
| 37 |
-
# def get_image_from_text(text_prompt, number_to_retrieve=1):
|
| 38 |
-
# prompt = model.encode(text_prompt)
|
| 39 |
-
# scores, retrieved_examples = ds_with_embeddings['train'].get_nearest_examples('img_embeddings', prompt, k=number_to_retrieve)
|
| 40 |
-
# images, captions = retrieved_examples['images'], retrieved_examples['caption_summary']
|
| 41 |
-
# return images, captions
|
| 42 |
|
| 43 |
def get_image_from_text(text_prompt, number_to_retrieve=1):
|
| 44 |
prompt = model.encode(text_prompt)
|
|
|
|
| 13 |
from PIL import Image
|
| 14 |
import io
|
| 15 |
|
|
|
|
| 16 |
def convert_to_image(byte_data):
|
| 17 |
+
"""Convert byte strings to images
|
| 18 |
+
"""
|
| 19 |
return Image.open(io.BytesIO(byte_data))
|
| 20 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 21 |
# Load the model and dataset
|
| 22 |
model = SentenceTransformer('clip-ViT-B-32')
|
| 23 |
ds_with_embeddings = load_dataset("kvriza8/clip_microscopy_image_text_embeddings")
|
|
|
|
| 26 |
# Initialize FAISS index once
|
| 27 |
ds_with_embeddings['train'].add_faiss_index(column='img_embeddings')
|
| 28 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 29 |
|
| 30 |
def get_image_from_text(text_prompt, number_to_retrieve=1):
|
| 31 |
prompt = model.encode(text_prompt)
|