Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -8,20 +8,27 @@ import requests
|
|
| 8 |
import json
|
| 9 |
from datetime import datetime
|
| 10 |
|
| 11 |
-
# Your existing
|
| 12 |
model = CLIPModel.from_pretrained("openai/clip-vit-base-patch32")
|
| 13 |
processor = CLIPProcessor.from_pretrained("openai/clip-vit-base-patch32")
|
| 14 |
index = faiss.read_index("partvision_index.faiss")
|
| 15 |
skus = pickle.load(open("partvision_sku_mapping.pkl", "rb"))
|
| 16 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 17 |
def get_cwr_data(skus_list):
|
| 18 |
if not skus_list:
|
| 19 |
return {}
|
| 20 |
-
skus_str = ",".join([str(
|
| 21 |
url = f"{CWR_URL}?id={CWR_ID}&version=3&format=json&fields=sku,price,qty,brand,name&skus={skus_str}"
|
| 22 |
try:
|
| 23 |
-
r = requests.get(url, timeout=
|
| 24 |
-
if r.status_code != 200
|
| 25 |
return {}
|
| 26 |
data = r.json()
|
| 27 |
result = {}
|
|
@@ -43,11 +50,11 @@ def identify(image):
|
|
| 43 |
if image is None:
|
| 44 |
return [], render_cart()
|
| 45 |
|
| 46 |
-
# YOUR REAL FAISS CODE — keep exactly as you have it
|
| 47 |
inputs = processor(images=image, return_tensors="pt")
|
| 48 |
with torch.no_grad():
|
| 49 |
query = model.get_image_features(**inputs)
|
| 50 |
query /= query.norm(dim=-1, keepdim=True)
|
|
|
|
| 51 |
D, I = index.search(query.cpu().numpy(), 10)
|
| 52 |
|
| 53 |
top_skus = []
|
|
|
|
| 8 |
import json
|
| 9 |
from datetime import datetime
|
| 10 |
|
| 11 |
+
# Your existing model and index
|
| 12 |
model = CLIPModel.from_pretrained("openai/clip-vit-base-patch32")
|
| 13 |
processor = CLIPProcessor.from_pretrained("openai/clip-vit-base-patch32")
|
| 14 |
index = faiss.read_index("partvision_index.faiss")
|
| 15 |
skus = pickle.load(open("partvision_sku_mapping.pkl", "rb"))
|
| 16 |
|
| 17 |
+
# CWR credentials
|
| 18 |
+
CWR_ID = "MPB_NDI3OTk5NDI3OTk5MTI4"
|
| 19 |
+
CWR_URL = "https://cwrdistribution.com/feeds/productdownload.php"
|
| 20 |
+
|
| 21 |
+
# Global cart — defined BEFORE any function uses it
|
| 22 |
+
cart = {}
|
| 23 |
+
|
| 24 |
def get_cwr_data(skus_list):
|
| 25 |
if not skus_list:
|
| 26 |
return {}
|
| 27 |
+
skus_str = ",".join([str(s) for s in skus_list])
|
| 28 |
url = f"{CWR_URL}?id={CWR_ID}&version=3&format=json&fields=sku,price,qty,brand,name&skus={skus_str}"
|
| 29 |
try:
|
| 30 |
+
r = requests.get(url, timeout=12)
|
| 31 |
+
if r.status_code != 200:
|
| 32 |
return {}
|
| 33 |
data = r.json()
|
| 34 |
result = {}
|
|
|
|
| 50 |
if image is None:
|
| 51 |
return [], render_cart()
|
| 52 |
|
|
|
|
| 53 |
inputs = processor(images=image, return_tensors="pt")
|
| 54 |
with torch.no_grad():
|
| 55 |
query = model.get_image_features(**inputs)
|
| 56 |
query /= query.norm(dim=-1, keepdim=True)
|
| 57 |
+
|
| 58 |
D, I = index.search(query.cpu().numpy(), 10)
|
| 59 |
|
| 60 |
top_skus = []
|