Spaces:
Sleeping
Sleeping
File size: 591 Bytes
eed5f5d |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 |
from PIL import Image
import requests
from io import BytesIO
from functions.loader import model, data
def load_image(url):
try:
response = requests.get(url)
img = Image.open(BytesIO(response.content))
except Exception:
img = Image.open("data/cat.jpg")
return img
def vectorize(descriptions):
embeddings = model.encode(descriptions)
return embeddings
def find_similar_shows(user_description, index, k=5):
query_vector = vectorize([user_description])
_, indices = index.search(query_vector, k)
return data.iloc[indices.flatten()] |