Spaces:
Runtime error
Runtime error
Commit
·
109869f
1
Parent(s):
226d235
fixed+improved UI
Browse files
app.py
CHANGED
|
@@ -6,26 +6,26 @@ from sentence_transformers import SentenceTransformer
|
|
| 6 |
from PIL import Image
|
| 7 |
from dotenv import load_dotenv
|
| 8 |
|
| 9 |
-
# Load environment variables
|
| 10 |
load_dotenv()
|
| 11 |
|
| 12 |
-
# Get Qdrant Cloud credentials (
|
| 13 |
QDRANT_URL = os.getenv("https://ff4da494-27b1-413c-ba58-d5ea14932fe1.europe-west3-0.gcp.cloud.qdrant.io:6333")
|
| 14 |
QDRANT_API_KEY = os.getenv("eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJhY2Nlc3MiOiJtIn0.jjeB1JgnUSlb1hOOKMdRpVvMrUER57-udT-X1AWXT1E")
|
| 15 |
COLLECTION_NAME = "lost_and_found"
|
| 16 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 17 |
# Load sentence transformer model
|
| 18 |
model = SentenceTransformer("clip-ViT-B-32")
|
| 19 |
|
| 20 |
-
# Initialize Qdrant client (Cloud if creds exist, else local)
|
| 21 |
-
if QDRANT_URL and QDRANT_API_KEY:
|
| 22 |
-
qclient = QdrantClient(
|
| 23 |
-
url=QDRANT_URL,
|
| 24 |
-
api_key=QDRANT_API_KEY,
|
| 25 |
-
)
|
| 26 |
-
else:
|
| 27 |
-
qclient = QdrantClient("localhost", port=6333)
|
| 28 |
-
|
| 29 |
# Create collection if it doesn’t exist
|
| 30 |
if not qclient.collection_exists(COLLECTION_NAME):
|
| 31 |
qclient.create_collection(
|
|
@@ -42,7 +42,7 @@ def add_item(image, description):
|
|
| 42 |
vector_desc = model.encode(description).tolist()
|
| 43 |
vector_img = model.encode(Image.open(image)).tolist()
|
| 44 |
|
| 45 |
-
# Upload to Qdrant (store both)
|
| 46 |
qclient.upsert(
|
| 47 |
collection_name=COLLECTION_NAME,
|
| 48 |
points=[
|
|
|
|
| 6 |
from PIL import Image
|
| 7 |
from dotenv import load_dotenv
|
| 8 |
|
| 9 |
+
# Load environment variables from .env
|
| 10 |
load_dotenv()
|
| 11 |
|
| 12 |
+
# Get Qdrant Cloud credentials (must be in .env or deployment secrets)
|
| 13 |
QDRANT_URL = os.getenv("https://ff4da494-27b1-413c-ba58-d5ea14932fe1.europe-west3-0.gcp.cloud.qdrant.io:6333")
|
| 14 |
QDRANT_API_KEY = os.getenv("eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJhY2Nlc3MiOiJtIn0.jjeB1JgnUSlb1hOOKMdRpVvMrUER57-udT-X1AWXT1E")
|
| 15 |
COLLECTION_NAME = "lost_and_found"
|
| 16 |
|
| 17 |
+
# Check creds
|
| 18 |
+
if not QDRANT_URL or not QDRANT_API_KEY:
|
| 19 |
+
raise RuntimeError(
|
| 20 |
+
"❌ Missing Qdrant Cloud credentials. Please set QDRANT_URL and QDRANT_API_KEY in your environment."
|
| 21 |
+
)
|
| 22 |
+
|
| 23 |
+
# Initialize Qdrant client
|
| 24 |
+
qclient = QdrantClient(url=QDRANT_URL, api_key=QDRANT_API_KEY)
|
| 25 |
+
|
| 26 |
# Load sentence transformer model
|
| 27 |
model = SentenceTransformer("clip-ViT-B-32")
|
| 28 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 29 |
# Create collection if it doesn’t exist
|
| 30 |
if not qclient.collection_exists(COLLECTION_NAME):
|
| 31 |
qclient.create_collection(
|
|
|
|
| 42 |
vector_desc = model.encode(description).tolist()
|
| 43 |
vector_img = model.encode(Image.open(image)).tolist()
|
| 44 |
|
| 45 |
+
# Upload to Qdrant (store both text & image vectors)
|
| 46 |
qclient.upsert(
|
| 47 |
collection_name=COLLECTION_NAME,
|
| 48 |
points=[
|