Spaces:
Sleeping
Sleeping
Update src/streamlit_app.py
Browse files- src/streamlit_app.py +11 -3
src/streamlit_app.py
CHANGED
|
@@ -41,7 +41,7 @@ def show_img(img_id, score=None, col=None):
|
|
| 41 |
img = Image.open(BytesIO(response.content))
|
| 42 |
|
| 43 |
# Lấy thông tin style từ img_id (giả sử bạn có một dataframe style)
|
| 44 |
-
img_style = style[style['id'] == img_id]
|
| 45 |
|
| 46 |
if not img_style.empty:
|
| 47 |
parts = []
|
|
@@ -82,6 +82,9 @@ def search_faiss(model, processor, index, id_map, prompt, top_k=5, device='cpu')
|
|
| 82 |
D, I = index.search(q, top_k)
|
| 83 |
|
| 84 |
st.write("FAISS search completed.")
|
|
|
|
|
|
|
|
|
|
| 85 |
return [(id_map[i], float(D[0][j])) for j, i in enumerate(I[0])]
|
| 86 |
|
| 87 |
def running(prompt, top_k=5):
|
|
@@ -97,11 +100,16 @@ def running(prompt, top_k=5):
|
|
| 97 |
cols = st.columns(5) # Chia thành 5 cột
|
| 98 |
col_idx = 0
|
| 99 |
for img_id, score in results:
|
|
|
|
| 100 |
show_img(img_id, score, col=cols[col_idx])
|
| 101 |
col_idx += 1
|
| 102 |
if col_idx == 5: # Sau khi hiển thị 5 ảnh, reset cột
|
| 103 |
col_idx = 0
|
| 104 |
|
|
|
|
|
|
|
|
|
|
|
|
|
| 105 |
# Đọc file CSV
|
| 106 |
|
| 107 |
current_dir = os.path.dirname(__file__)
|
|
@@ -174,9 +182,9 @@ The goal of this system is to retrieve the most relevant fashion images based on
|
|
| 174 |
# Example to show some images
|
| 175 |
st.subheader("Some Sample Images and Their Captions:")
|
| 176 |
example = [13422, 10037, 38246, 23273, 2008]
|
| 177 |
-
|
| 178 |
for idx, img_id in enumerate(example):
|
| 179 |
-
show_img(img_id, None,
|
| 180 |
|
| 181 |
# Chạy ví dụ với prompt
|
| 182 |
st.subheader("Example Usage: Enter a Prompt to Retrieve Related Images")
|
|
|
|
| 41 |
img = Image.open(BytesIO(response.content))
|
| 42 |
|
| 43 |
# Lấy thông tin style từ img_id (giả sử bạn có một dataframe style)
|
| 44 |
+
img_style = style[style['id'] == int(img_id)]
|
| 45 |
|
| 46 |
if not img_style.empty:
|
| 47 |
parts = []
|
|
|
|
| 82 |
D, I = index.search(q, top_k)
|
| 83 |
|
| 84 |
st.write("FAISS search completed.")
|
| 85 |
+
st.write("Indices returned:", I[0])
|
| 86 |
+
st.write("Scores returned:", D[0])
|
| 87 |
+
st.write("ID map keys sample:", list(id_map.keys())[:10])
|
| 88 |
return [(id_map[i], float(D[0][j])) for j, i in enumerate(I[0])]
|
| 89 |
|
| 90 |
def running(prompt, top_k=5):
|
|
|
|
| 100 |
cols = st.columns(5) # Chia thành 5 cột
|
| 101 |
col_idx = 0
|
| 102 |
for img_id, score in results:
|
| 103 |
+
st.write(f"results: {img_id} và {score}")
|
| 104 |
show_img(img_id, score, col=cols[col_idx])
|
| 105 |
col_idx += 1
|
| 106 |
if col_idx == 5: # Sau khi hiển thị 5 ảnh, reset cột
|
| 107 |
col_idx = 0
|
| 108 |
|
| 109 |
+
if not results:
|
| 110 |
+
st.warning("No results were returned from FAISS. Check your prompt or embedding.")
|
| 111 |
+
|
| 112 |
+
|
| 113 |
# Đọc file CSV
|
| 114 |
|
| 115 |
current_dir = os.path.dirname(__file__)
|
|
|
|
| 182 |
# Example to show some images
|
| 183 |
st.subheader("Some Sample Images and Their Captions:")
|
| 184 |
example = [13422, 10037, 38246, 23273, 2008]
|
| 185 |
+
example_cols = st.columns(5) # Chia thành 5 cột
|
| 186 |
for idx, img_id in enumerate(example):
|
| 187 |
+
show_img(img_id, None, example_cols[idx])
|
| 188 |
|
| 189 |
# Chạy ví dụ với prompt
|
| 190 |
st.subheader("Example Usage: Enter a Prompt to Retrieve Related Images")
|