leedoming commited on
Commit
ce67f34
Β·
verified Β·
1 Parent(s): 97480db

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +28 -18
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
- selected_detection = next(d for d in detections if f"{d['category']} (Confidence: {d['confidence']:.2f})" == selected_category)
148
- cropped_image = crop_image(query_image, selected_detection['bbox'])
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"):