Thiago Hersan
commited on
Commit
·
d6f2704
1
Parent(s):
d343dcc
remove lfs
Browse files- .gitattributes +0 -1
- app.py +17 -1
.gitattributes
DELETED
|
@@ -1 +0,0 @@
|
|
| 1 |
-
art-crops_siglip2.json filter=lfs diff=lfs merge=lfs -text
|
|
|
|
|
|
app.py
CHANGED
|
@@ -5,17 +5,33 @@ import requests
|
|
| 5 |
import torch
|
| 6 |
|
| 7 |
from io import BytesIO
|
|
|
|
| 8 |
from PIL import Image as PImage
|
|
|
|
|
|
|
| 9 |
from sklearn.metrics.pairwise import euclidean_distances, cosine_distances
|
| 10 |
from transformers import AutoModel, AutoProcessor
|
| 11 |
|
|
|
|
|
|
|
| 12 |
MODEL_NAME = "google/siglip2-giant-opt-patch16-256"
|
| 13 |
DEVICE = "cuda" if torch.cuda.is_available() else "cpu"
|
| 14 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 15 |
processor = AutoProcessor.from_pretrained(MODEL_NAME)
|
| 16 |
model = AutoModel.from_pretrained(MODEL_NAME)#.to(DEVICE)
|
| 17 |
|
| 18 |
-
|
|
|
|
| 19 |
embeddings_data = json.load(ifp)
|
| 20 |
|
| 21 |
crop_names = np.array(list(embeddings_data.keys()))
|
|
|
|
| 5 |
import torch
|
| 6 |
|
| 7 |
from io import BytesIO
|
| 8 |
+
from os import path
|
| 9 |
from PIL import Image as PImage
|
| 10 |
+
from urllib import request
|
| 11 |
+
|
| 12 |
from sklearn.metrics.pairwise import euclidean_distances, cosine_distances
|
| 13 |
from transformers import AutoModel, AutoProcessor
|
| 14 |
|
| 15 |
+
EMBEDS_URL = "https://media.githubusercontent.com/media/acervos-digitais/herbario-data/main/json/20250705_art-crops.json"
|
| 16 |
+
|
| 17 |
MODEL_NAME = "google/siglip2-giant-opt-patch16-256"
|
| 18 |
DEVICE = "cuda" if torch.cuda.is_available() else "cpu"
|
| 19 |
|
| 20 |
+
def download_file(url, local_path="."):
|
| 21 |
+
file_name = url.split("/")[-1]
|
| 22 |
+
file_path = path.join(local_path, file_name)
|
| 23 |
+
|
| 24 |
+
with request.urlopen(request.Request(url), timeout=30.0) as response:
|
| 25 |
+
if response.status == 200:
|
| 26 |
+
with open(file_path, "wb") as f:
|
| 27 |
+
f.write(response.read())
|
| 28 |
+
return file_path
|
| 29 |
+
|
| 30 |
processor = AutoProcessor.from_pretrained(MODEL_NAME)
|
| 31 |
model = AutoModel.from_pretrained(MODEL_NAME)#.to(DEVICE)
|
| 32 |
|
| 33 |
+
embeddings_path = download_file(EMBEDS_URL)
|
| 34 |
+
with open(embeddings_path, "r") as ifp:
|
| 35 |
embeddings_data = json.load(ifp)
|
| 36 |
|
| 37 |
crop_names = np.array(list(embeddings_data.keys()))
|