Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
@@ -124,29 +124,30 @@ def detect_clothing(image):
|
|
124 |
def crop_image(image, bbox):
|
125 |
return image.crop((bbox[0], bbox[1], bbox[2], bbox[3]))
|
126 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
127 |
# Streamlit app
|
128 |
st.title("Advanced Fashion Search App")
|
129 |
|
130 |
-
|
131 |
-
|
132 |
-
|
133 |
-
query_image_url = st.text_input("Enter image URL:")
|
134 |
if st.button("Detect Clothing"):
|
135 |
-
if query_image_url:
|
136 |
-
query_image = load_image_from_url(query_image_url)
|
137 |
if query_image is not None:
|
138 |
-
st.
|
139 |
-
detections = detect_clothing(query_image)
|
140 |
-
|
141 |
-
|
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,30 +155,42 @@ if search_type == "Image URL":
|
|
154 |
else:
|
155 |
st.warning("Please enter an image URL.")
|
156 |
|
157 |
-
|
158 |
-
|
159 |
-
|
160 |
-
|
161 |
-
|
162 |
-
|
163 |
-
|
164 |
-
|
165 |
-
|
166 |
-
|
167 |
-
|
168 |
-
|
169 |
-
|
170 |
-
|
171 |
-
|
172 |
-
|
173 |
-
|
174 |
-
|
175 |
-
|
176 |
-
|
177 |
-
|
178 |
-
|
179 |
-
|
180 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
181 |
|
182 |
else: # Text search
|
183 |
query_text = st.text_input("Enter search text:")
|
|
|
124 |
def crop_image(image, bbox):
|
125 |
return image.crop((bbox[0], bbox[1], bbox[2], bbox[3]))
|
126 |
|
127 |
+
# μΈμ
μν μ΄κΈ°ν
|
128 |
+
if 'step' not in st.session_state:
|
129 |
+
st.session_state.step = 'input'
|
130 |
+
if 'query_image_url' not in st.session_state:
|
131 |
+
st.session_state.query_image_url = ''
|
132 |
+
if 'detections' not in st.session_state:
|
133 |
+
st.session_state.detections = []
|
134 |
+
if 'selected_category' not in st.session_state:
|
135 |
+
st.session_state.selected_category = None
|
136 |
+
|
137 |
# Streamlit app
|
138 |
st.title("Advanced Fashion Search App")
|
139 |
|
140 |
+
# λ¨κ³λ³ μ²λ¦¬
|
141 |
+
if st.session_state.step == 'input':
|
142 |
+
st.session_state.query_image_url = st.text_input("Enter image URL:", st.session_state.query_image_url)
|
|
|
143 |
if st.button("Detect Clothing"):
|
144 |
+
if st.session_state.query_image_url:
|
145 |
+
query_image = load_image_from_url(st.session_state.query_image_url)
|
146 |
if query_image is not None:
|
147 |
+
st.session_state.query_image = query_image
|
148 |
+
st.session_state.detections = detect_clothing(query_image)
|
149 |
+
if st.session_state.detections:
|
150 |
+
st.session_state.step = 'select_category'
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
151 |
else:
|
152 |
st.warning("No clothing items detected in the image.")
|
153 |
else:
|
|
|
155 |
else:
|
156 |
st.warning("Please enter an image URL.")
|
157 |
|
158 |
+
elif st.session_state.step == 'select_category':
|
159 |
+
st.image(st.session_state.query_image, caption="Query Image", use_column_width=True)
|
160 |
+
st.subheader("Detected Clothing Items:")
|
161 |
+
options = [f"{d['category']} (Confidence: {d['confidence']:.2f})" for d in st.session_state.detections]
|
162 |
+
selected_option = st.selectbox("Select a category to search:", options)
|
163 |
+
if st.button("Search Similar Items"):
|
164 |
+
st.session_state.selected_category = selected_option
|
165 |
+
st.session_state.step = 'show_results'
|
166 |
+
|
167 |
+
elif st.session_state.step == 'show_results':
|
168 |
+
st.image(st.session_state.query_image, caption="Query Image", use_column_width=True)
|
169 |
+
selected_detection = next(d for d in st.session_state.detections
|
170 |
+
if f"{d['category']} (Confidence: {d['confidence']:.2f})" == st.session_state.selected_category)
|
171 |
+
cropped_image = crop_image(st.session_state.query_image, selected_detection['bbox'])
|
172 |
+
st.image(cropped_image, caption="Cropped Image", use_column_width=True)
|
173 |
+
query_embedding = get_image_embedding(cropped_image)
|
174 |
+
similar_images = find_similar_images(query_embedding)
|
175 |
+
|
176 |
+
st.subheader("Similar Items:")
|
177 |
+
for img in similar_images:
|
178 |
+
col1, col2 = st.columns(2)
|
179 |
+
with col1:
|
180 |
+
st.image(img['info']['image_url'], use_column_width=True)
|
181 |
+
with col2:
|
182 |
+
st.write(f"Name: {img['info']['name']}")
|
183 |
+
st.write(f"Brand: {img['info']['brand']}")
|
184 |
+
st.write(f"Category: {img['info']['category']}")
|
185 |
+
st.write(f"Price: {img['info']['price']}")
|
186 |
+
st.write(f"Discount: {img['info']['discount']}%")
|
187 |
+
st.write(f"Similarity: {img['similarity']:.2f}")
|
188 |
+
|
189 |
+
if st.button("Start New Search"):
|
190 |
+
st.session_state.step = 'input'
|
191 |
+
st.session_state.query_image_url = ''
|
192 |
+
st.session_state.detections = []
|
193 |
+
st.session_state.selected_category = None
|
194 |
|
195 |
else: # Text search
|
196 |
query_text = st.text_input("Enter search text:")
|