Spaces:
Runtime error
Runtime error
initial commit
Browse files- app.py +41 -0
- images.csv +0 -0
- requirements.txt +4 -0
app.py
ADDED
|
@@ -0,0 +1,41 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# Initialize a retriever using Qdrant and SentenceTransformer embeddings
|
| 2 |
+
from langchain.vectorstores import Qdrant
|
| 3 |
+
from langchain.retrievers import EnsembleRetriever
|
| 4 |
+
from langchain.embeddings import SentenceTransformerEmbeddings
|
| 5 |
+
from qdrant_client import QdrantClient
|
| 6 |
+
import pandas as pd
|
| 7 |
+
import gradio as gr
|
| 8 |
+
|
| 9 |
+
|
| 10 |
+
embeddings = SentenceTransformerEmbeddings(model_name='sentence-transformers/clip-ViT-B-32')
|
| 11 |
+
|
| 12 |
+
def get_results(search_results):
|
| 13 |
+
filtered_img_ids = [doc.metadata.get("image_id") for doc in search_results]
|
| 14 |
+
return filtered_img_ids
|
| 15 |
+
|
| 16 |
+
vector_db_key = user_secrets.get_secret("vector_db_key")
|
| 17 |
+
|
| 18 |
+
client = QdrantClient(
|
| 19 |
+
url="https://763bc1da-0673-4535-91ac-b5538ec0287f.us-east4-0.gcp.cloud.qdrant.io:6333",
|
| 20 |
+
api_key='UOqiBgqhhu8BBWP98mwjGl7h4IhL2vMAqzO4EI9PEB66A50n9GoIiQ',
|
| 21 |
+
) # Persists changes to disk, fast prototyping
|
| 22 |
+
|
| 23 |
+
COLLECTION_NAME="semantic_image_search"
|
| 24 |
+
|
| 25 |
+
|
| 26 |
+
dense_vector_retriever = Qdrant(client, COLLECTION_NAME, embeddings)
|
| 27 |
+
images_data = pd.read_csv("/kaggle/input/fashion-product-images-dataset/fashion-dataset/images.csv", on_bad_lines='skip')
|
| 28 |
+
|
| 29 |
+
def get_link(query):
|
| 30 |
+
Search_Query = query
|
| 31 |
+
neutral_retiever = EnsembleRetriever(retrievers=[dense_vector_retriever.as_retriever()])
|
| 32 |
+
result = neutral_retiever.get_relevant_documents(Search_Query)
|
| 33 |
+
filtered_images = get_results(result)
|
| 34 |
+
filtered_img_ids = [doc.metadata.get("image_id") for doc in result]
|
| 35 |
+
|
| 36 |
+
links = [images_data.loc[id, 'link'] for id in filtered_img_ids]
|
| 37 |
+
# final = '[' + ','.join(links) + ']'
|
| 38 |
+
return links
|
| 39 |
+
|
| 40 |
+
# print(get_link("black shirt for men"))
|
| 41 |
+
gr.Interface(fn = get_link, inputs = 'textbox', outputs = 'textbox').launch()
|
images.csv
ADDED
|
The diff for this file is too large to render.
See raw diff
|
|
|
requirements.txt
ADDED
|
@@ -0,0 +1,4 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
qdrant-client
|
| 2 |
+
langchain
|
| 3 |
+
sentence_transformers
|
| 4 |
+
gradio
|