Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
@@ -124,6 +124,35 @@ def detect_clothing(image):
|
|
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'
|
@@ -154,10 +183,16 @@ if st.session_state.step == 'input':
|
|
154 |
st.error("Failed to load the image. Please try another URL.")
|
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"):
|
|
|
124 |
def crop_image(image, bbox):
|
125 |
return image.crop((bbox[0], bbox[1], bbox[2], bbox[3]))
|
126 |
|
127 |
+
def adjust_bounding_boxes(image, detections):
|
128 |
+
img_height, img_width = image.size
|
129 |
+
rects = []
|
130 |
+
for detection in detections:
|
131 |
+
x1, y1, x2, y2 = detection['bbox']
|
132 |
+
rects.append({
|
133 |
+
"left": x1 / img_width,
|
134 |
+
"top": y1 / img_height,
|
135 |
+
"width": (x2 - x1) / img_width,
|
136 |
+
"height": (y2 - y1) / img_height,
|
137 |
+
"label": detection['category']
|
138 |
+
})
|
139 |
+
|
140 |
+
adjusted_rects = st_img_label(image, box_color="red", rects=rects)
|
141 |
+
|
142 |
+
adjusted_detections = []
|
143 |
+
for rect, detection in zip(adjusted_rects, detections):
|
144 |
+
x1 = rect["left"] * img_width
|
145 |
+
y1 = rect["top"] * img_height
|
146 |
+
x2 = x1 + (rect["width"] * img_width)
|
147 |
+
y2 = y1 + (rect["height"] * img_height)
|
148 |
+
adjusted_detections.append({
|
149 |
+
'category': rect["label"],
|
150 |
+
'bbox': [int(x1), int(y1), int(x2), int(y2)],
|
151 |
+
'confidence': detection['confidence']
|
152 |
+
})
|
153 |
+
|
154 |
+
return adjusted_detections
|
155 |
+
|
156 |
# ์ธ์
์ํ ์ด๊ธฐํ
|
157 |
if 'step' not in st.session_state:
|
158 |
st.session_state.step = 'input'
|
|
|
183 |
st.error("Failed to load the image. Please try another URL.")
|
184 |
else:
|
185 |
st.warning("Please enter an image URL.")
|
186 |
+
pass
|
187 |
|
188 |
elif st.session_state.step == 'select_category':
|
189 |
st.image(st.session_state.query_image, caption="Query Image", use_column_width=True)
|
190 |
st.subheader("Detected Clothing Items:")
|
191 |
+
|
192 |
+
# ๊ฒฝ๊ณ ์์ ์กฐ์ ๊ธฐ๋ฅ ์ถ๊ฐ
|
193 |
+
adjusted_detections = adjust_bounding_boxes(st.session_state.query_image, st.session_state.detections)
|
194 |
+
st.session_state.detections = adjusted_detections
|
195 |
+
|
196 |
options = [f"{d['category']} (Confidence: {d['confidence']:.2f})" for d in st.session_state.detections]
|
197 |
selected_option = st.selectbox("Select a category to search:", options)
|
198 |
if st.button("Search Similar Items"):
|