Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
@@ -139,29 +139,14 @@ if search_type == "Image URL":
|
|
139 |
detections = detect_clothing(query_image)
|
140 |
|
141 |
if detections:
|
|
|
142 |
st.subheader("Detected Clothing Items:")
|
143 |
selected_category = st.selectbox("Select a category to search:",
|
144 |
[f"{d['category']} (Confidence: {d['confidence']:.2f})" for d in detections])
|
145 |
|
146 |
if st.button("Search Similar Items"):
|
147 |
-
|
148 |
-
|
149 |
-
st.image(cropped_image, caption="Cropped Image", use_column_width=True)
|
150 |
-
query_embedding = get_image_embedding(cropped_image)
|
151 |
-
similar_images = find_similar_images(query_embedding)
|
152 |
-
|
153 |
-
st.subheader("Similar Items:")
|
154 |
-
for img in similar_images:
|
155 |
-
col1, col2 = st.columns(2)
|
156 |
-
with col1:
|
157 |
-
st.image(img['info']['image_url'], use_column_width=True)
|
158 |
-
with col2:
|
159 |
-
st.write(f"Name: {img['info']['name']}")
|
160 |
-
st.write(f"Brand: {img['info']['brand']}")
|
161 |
-
st.write(f"Category: {img['info']['category']}")
|
162 |
-
st.write(f"Price: {img['info']['price']}")
|
163 |
-
st.write(f"Discount: {img['info']['discount']}%")
|
164 |
-
st.write(f"Similarity: {img['similarity']:.2f}")
|
165 |
else:
|
166 |
st.warning("No clothing items detected in the image.")
|
167 |
else:
|
@@ -169,6 +154,31 @@ if search_type == "Image URL":
|
|
169 |
else:
|
170 |
st.warning("Please enter an image URL.")
|
171 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
172 |
else: # Text search
|
173 |
query_text = st.text_input("Enter search text:")
|
174 |
if st.button("Search by Text"):
|
|
|
139 |
detections = detect_clothing(query_image)
|
140 |
|
141 |
if detections:
|
142 |
+
st.session_state.detections = detections # μΈμ
μνμ detections μ μ₯
|
143 |
st.subheader("Detected Clothing Items:")
|
144 |
selected_category = st.selectbox("Select a category to search:",
|
145 |
[f"{d['category']} (Confidence: {d['confidence']:.2f})" for d in detections])
|
146 |
|
147 |
if st.button("Search Similar Items"):
|
148 |
+
st.session_state.selected_category = selected_category # μ νλ μΉ΄ν
κ³ λ¦¬ μ μ₯
|
149 |
+
st.session_state.search_clicked = True # κ²μ λ²νΌ ν΄λ¦ μν μ μ₯
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
150 |
else:
|
151 |
st.warning("No clothing items detected in the image.")
|
152 |
else:
|
|
|
154 |
else:
|
155 |
st.warning("Please enter an image URL.")
|
156 |
|
157 |
+
# κ²μ κ²°κ³Ό νμ λ‘μ§
|
158 |
+
if 'search_clicked' in st.session_state and st.session_state.search_clicked:
|
159 |
+
selected_detection = next(d for d in st.session_state.detections
|
160 |
+
if f"{d['category']} (Confidence: {d['confidence']:.2f})" == st.session_state.selected_category)
|
161 |
+
cropped_image = crop_image(query_image, selected_detection['bbox'])
|
162 |
+
st.image(cropped_image, caption="Cropped Image", use_column_width=True)
|
163 |
+
query_embedding = get_image_embedding(cropped_image)
|
164 |
+
similar_images = find_similar_images(query_embedding)
|
165 |
+
|
166 |
+
st.subheader("Similar Items:")
|
167 |
+
for img in similar_images:
|
168 |
+
col1, col2 = st.columns(2)
|
169 |
+
with col1:
|
170 |
+
st.image(img['info']['image_url'], use_column_width=True)
|
171 |
+
with col2:
|
172 |
+
st.write(f"Name: {img['info']['name']}")
|
173 |
+
st.write(f"Brand: {img['info']['brand']}")
|
174 |
+
st.write(f"Category: {img['info']['category']}")
|
175 |
+
st.write(f"Price: {img['info']['price']}")
|
176 |
+
st.write(f"Discount: {img['info']['discount']}%")
|
177 |
+
st.write(f"Similarity: {img['similarity']:.2f}")
|
178 |
+
|
179 |
+
# κ²μ μλ£ ν μν μ΄κΈ°ν
|
180 |
+
st.session_state.search_clicked = False
|
181 |
+
|
182 |
else: # Text search
|
183 |
query_text = st.text_input("Enter search text:")
|
184 |
if st.button("Search by Text"):
|