Spaces:
Runtime error
Runtime error
Commit ·
a7331e7
1
Parent(s): 0f913e1
Update main.py
Browse files
main.py
CHANGED
|
@@ -2,6 +2,7 @@ from fastapi import FastAPI
|
|
| 2 |
from pydantic import BaseModel
|
| 3 |
from typing import List
|
| 4 |
from PIL import Image
|
|
|
|
| 5 |
from sentence_transformers import SentenceTransformer, util
|
| 6 |
|
| 7 |
class Item(BaseModel):
|
|
@@ -31,7 +32,10 @@ def predict(item: Item):
|
|
| 31 |
# encoded_image = model.encode(Image.open(filepath))
|
| 32 |
#image_names = list(glob.glob('./*.jpg'))
|
| 33 |
#print("Images:", len(image_names))
|
| 34 |
-
|
|
|
|
|
|
|
|
|
|
| 35 |
|
| 36 |
# Now we run the clustering algorithm. This function compares images aganist
|
| 37 |
# all other images and returns a list with the pairs that have the highest
|
|
|
|
| 2 |
from pydantic import BaseModel
|
| 3 |
from typing import List
|
| 4 |
from PIL import Image
|
| 5 |
+
import io
|
| 6 |
from sentence_transformers import SentenceTransformer, util
|
| 7 |
|
| 8 |
class Item(BaseModel):
|
|
|
|
| 32 |
# encoded_image = model.encode(Image.open(filepath))
|
| 33 |
#image_names = list(glob.glob('./*.jpg'))
|
| 34 |
#print("Images:", len(image_names))
|
| 35 |
+
|
| 36 |
+
|
| 37 |
+
|
| 38 |
+
encoded_image = model.encode([Image.open(io.BytesIO(item.image1)), Image.open(io.BytesIO(item.image2))], batch_size=128, convert_to_tensor=True, show_progress_bar=True)
|
| 39 |
|
| 40 |
# Now we run the clustering algorithm. This function compares images aganist
|
| 41 |
# all other images and returns a list with the pairs that have the highest
|