Spaces:
Sleeping
Sleeping
Update src/streamlit_app.py
Browse files- src/streamlit_app.py +8 -8
src/streamlit_app.py
CHANGED
|
@@ -56,7 +56,7 @@ def show_img(img_id, score=None, col=None):
|
|
| 56 |
|
| 57 |
text = '- '.join(parts)
|
| 58 |
if score:
|
| 59 |
-
text += f'\n Score: {score}'
|
| 60 |
|
| 61 |
# Hiển thị ảnh trong cột
|
| 62 |
if col:
|
|
@@ -84,8 +84,8 @@ def search_faiss(model, processor, index, id_map, prompt, top_k=5, device='cpu')
|
|
| 84 |
D, I = index.search(q, top_k)
|
| 85 |
|
| 86 |
st.write("FAISS search completed.")
|
| 87 |
-
st.write("Indices returned:", I[0])
|
| 88 |
-
st.write("Scores returned:", D[0])
|
| 89 |
# st.write("ID map keys sample:", list(id_map.keys())[:10])
|
| 90 |
return [(id_map[i], float(D[0][j])) for j, i in enumerate(I[0])]
|
| 91 |
|
|
@@ -102,7 +102,7 @@ def running(prompt, top_k=5):
|
|
| 102 |
cols = st.columns(5) # Chia thành 5 cột
|
| 103 |
col_idx = 0
|
| 104 |
for img_id, score in results:
|
| 105 |
-
st.write(f"results: {img_id} và {score}")
|
| 106 |
show_img(img_id, score, col=cols[col_idx])
|
| 107 |
col_idx += 1
|
| 108 |
if col_idx == 5: # Sau khi hiển thị 5 ảnh, reset cột
|
|
@@ -165,12 +165,12 @@ processor = CLIPProcessor.from_pretrained(
|
|
| 165 |
with open(mapping_path, "rb") as f:
|
| 166 |
id_map = pickle.load(f)
|
| 167 |
|
| 168 |
-
st.title("Fashion Product Image
|
| 169 |
|
| 170 |
st.markdown("""
|
| 171 |
### **Overview**
|
| 172 |
|
| 173 |
-
In this project, I demonstrate an **Image
|
| 174 |
|
| 175 |
The goal of this system is to retrieve the most relevant fashion images based on a given text prompt (e.g., "red dress") and vice versa. With this system, users can search for fashion products in a more intuitive, text-based manner.
|
| 176 |
|
|
@@ -182,14 +182,14 @@ The goal of this system is to retrieve the most relevant fashion images based on
|
|
| 182 |
""")
|
| 183 |
|
| 184 |
# Example to show some images
|
| 185 |
-
st.subheader("Some
|
| 186 |
example = [13422, 10037, 38246, 23273, 2008]
|
| 187 |
example_cols = st.columns(5) # Chia thành 5 cột
|
| 188 |
for idx, img_id in enumerate(example):
|
| 189 |
show_img(img_id, None, example_cols[idx])
|
| 190 |
|
| 191 |
# Chạy ví dụ với prompt
|
| 192 |
-
st.subheader("Example
|
| 193 |
prompt_input = st.text_input("Enter a prompt", "a red Apparel dress")
|
| 194 |
top_k_input = st.number_input("Enter the number of results (top_k)", min_value=1, max_value=10, value=5)
|
| 195 |
|
|
|
|
| 56 |
|
| 57 |
text = '- '.join(parts)
|
| 58 |
if score:
|
| 59 |
+
text += f'\n\n Score: {score:.2f}'
|
| 60 |
|
| 61 |
# Hiển thị ảnh trong cột
|
| 62 |
if col:
|
|
|
|
| 84 |
D, I = index.search(q, top_k)
|
| 85 |
|
| 86 |
st.write("FAISS search completed.")
|
| 87 |
+
# st.write("Indices returned:", I[0])
|
| 88 |
+
# st.write("Scores returned:", D[0])
|
| 89 |
# st.write("ID map keys sample:", list(id_map.keys())[:10])
|
| 90 |
return [(id_map[i], float(D[0][j])) for j, i in enumerate(I[0])]
|
| 91 |
|
|
|
|
| 102 |
cols = st.columns(5) # Chia thành 5 cột
|
| 103 |
col_idx = 0
|
| 104 |
for img_id, score in results:
|
| 105 |
+
# st.write(f"results: {img_id} và {score}")
|
| 106 |
show_img(img_id, score, col=cols[col_idx])
|
| 107 |
col_idx += 1
|
| 108 |
if col_idx == 5: # Sau khi hiển thị 5 ảnh, reset cột
|
|
|
|
| 165 |
with open(mapping_path, "rb") as f:
|
| 166 |
id_map = pickle.load(f)
|
| 167 |
|
| 168 |
+
st.title("Fashion Product Image Retrieval")
|
| 169 |
|
| 170 |
st.markdown("""
|
| 171 |
### **Overview**
|
| 172 |
|
| 173 |
+
In this project, I demonstrate an **Image Retrieval** system for fashion products. The system uses a fine-tuned **CLIP model** (`clip-vit-base-patch32`) to match images with relevant text descriptions. We have a dataset of **1000 fashion product images**, stored on **Amazon S3**. Each image is associated with detailed product descriptions, such as **product type**, **color**, **category**, and **brand**.
|
| 174 |
|
| 175 |
The goal of this system is to retrieve the most relevant fashion images based on a given text prompt (e.g., "red dress") and vice versa. With this system, users can search for fashion products in a more intuitive, text-based manner.
|
| 176 |
|
|
|
|
| 182 |
""")
|
| 183 |
|
| 184 |
# Example to show some images
|
| 185 |
+
st.subheader("Some sample images and their captions:")
|
| 186 |
example = [13422, 10037, 38246, 23273, 2008]
|
| 187 |
example_cols = st.columns(5) # Chia thành 5 cột
|
| 188 |
for idx, img_id in enumerate(example):
|
| 189 |
show_img(img_id, None, example_cols[idx])
|
| 190 |
|
| 191 |
# Chạy ví dụ với prompt
|
| 192 |
+
st.subheader("Example usage: enter a prompt to retrieve related images")
|
| 193 |
prompt_input = st.text_input("Enter a prompt", "a red Apparel dress")
|
| 194 |
top_k_input = st.number_input("Enter the number of results (top_k)", min_value=1, max_value=10, value=5)
|
| 195 |
|