Spaces:
Running on Zero
Running on Zero
Add debug logging to identify the error
Browse files- hf-space/app.py +13 -1
hf-space/app.py
CHANGED
|
@@ -12,6 +12,8 @@ from PIL import Image
|
|
| 12 |
PINECONE_API_KEY = os.environ.get('PINECONE_API_KEY')
|
| 13 |
PINECONE_HOST = os.environ.get('PINECONE_HOST')
|
| 14 |
|
|
|
|
|
|
|
| 15 |
# Model (loaded on first use)
|
| 16 |
model = None
|
| 17 |
|
|
@@ -87,11 +89,19 @@ def search(image):
|
|
| 87 |
return "No image provided"
|
| 88 |
|
| 89 |
try:
|
|
|
|
| 90 |
embedding = get_embedding(image)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 91 |
products = query_pinecone(embedding)
|
|
|
|
| 92 |
|
| 93 |
if not products:
|
| 94 |
-
return "No similar products found"
|
| 95 |
|
| 96 |
result = "\n".join([
|
| 97 |
f"{i+1}. {p['title']} ({p['handle']}) - score: {p['score']:.3f}"
|
|
@@ -99,6 +109,8 @@ def search(image):
|
|
| 99 |
])
|
| 100 |
return result
|
| 101 |
except Exception as e:
|
|
|
|
|
|
|
| 102 |
return f"Error: {str(e)}"
|
| 103 |
|
| 104 |
|
|
|
|
| 12 |
PINECONE_API_KEY = os.environ.get('PINECONE_API_KEY')
|
| 13 |
PINECONE_HOST = os.environ.get('PINECONE_HOST')
|
| 14 |
|
| 15 |
+
print(f"Pinecone configured: Key={'yes' if PINECONE_API_KEY else 'NO'}, Host={'yes' if PINECONE_HOST else 'NO'}")
|
| 16 |
+
|
| 17 |
# Model (loaded on first use)
|
| 18 |
model = None
|
| 19 |
|
|
|
|
| 89 |
return "No image provided"
|
| 90 |
|
| 91 |
try:
|
| 92 |
+
print("Getting embedding...")
|
| 93 |
embedding = get_embedding(image)
|
| 94 |
+
print(f"Embedding length: {len(embedding)}")
|
| 95 |
+
|
| 96 |
+
if not PINECONE_API_KEY or not PINECONE_HOST:
|
| 97 |
+
return f"Pinecone not configured. Key: {'set' if PINECONE_API_KEY else 'missing'}, Host: {'set' if PINECONE_HOST else 'missing'}"
|
| 98 |
+
|
| 99 |
+
print("Querying Pinecone...")
|
| 100 |
products = query_pinecone(embedding)
|
| 101 |
+
print(f"Found {len(products)} products")
|
| 102 |
|
| 103 |
if not products:
|
| 104 |
+
return "No similar products found (check if index has data)"
|
| 105 |
|
| 106 |
result = "\n".join([
|
| 107 |
f"{i+1}. {p['title']} ({p['handle']}) - score: {p['score']:.3f}"
|
|
|
|
| 109 |
])
|
| 110 |
return result
|
| 111 |
except Exception as e:
|
| 112 |
+
import traceback
|
| 113 |
+
traceback.print_exc()
|
| 114 |
return f"Error: {str(e)}"
|
| 115 |
|
| 116 |
|