Spaces:
Sleeping
Sleeping
Fix: Corrected detect_objects function call and return handling
Browse files
app.py
CHANGED
|
@@ -176,30 +176,31 @@ def main():
|
|
| 176 |
if st.button("π Analyze Image", type="primary"):
|
| 177 |
with st.spinner("π Detecting objects..."):
|
| 178 |
# Perform object detection
|
| 179 |
-
|
| 180 |
-
|
| 181 |
-
if results and len(results['detections']) > 0:
|
| 182 |
-
# Extract detected objects
|
| 183 |
-
detected_objects = [det['class'] for det in results['detections']]
|
| 184 |
|
|
|
|
| 185 |
# Display results
|
| 186 |
st.success(f"β
Detected {len(detected_objects)} objects!")
|
| 187 |
|
| 188 |
# Show annotated image
|
| 189 |
st.markdown("### π― Detection Results")
|
| 190 |
-
|
| 191 |
-
st.image(results['annotated_image'], caption="Detected Objects", use_column_width=True)
|
| 192 |
|
| 193 |
# Show detection details
|
| 194 |
st.markdown("### π Detected Objects")
|
| 195 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 196 |
col_a, col_b, col_c = st.columns(3)
|
| 197 |
with col_a:
|
| 198 |
-
st.metric("Object",
|
| 199 |
with col_b:
|
| 200 |
-
st.metric("
|
| 201 |
with col_c:
|
| 202 |
-
st.metric("
|
| 203 |
|
| 204 |
# AI Explanation
|
| 205 |
if os.getenv("OPENAI_API_KEY"):
|
|
@@ -214,7 +215,7 @@ def main():
|
|
| 214 |
st.warning("π Add OPENAI_API_KEY in settings for AI explanations")
|
| 215 |
|
| 216 |
else:
|
| 217 |
-
st.warning("β No objects detected
|
| 218 |
|
| 219 |
with col2:
|
| 220 |
st.markdown("### π Detection Statistics")
|
|
|
|
| 176 |
if st.button("π Analyze Image", type="primary"):
|
| 177 |
with st.spinner("π Detecting objects..."):
|
| 178 |
# Perform object detection
|
| 179 |
+
annotated_img, detected_objects = detect_objects(image)
|
|
|
|
|
|
|
|
|
|
|
|
|
| 180 |
|
| 181 |
+
if detected_objects and len(detected_objects) > 0:
|
| 182 |
# Display results
|
| 183 |
st.success(f"β
Detected {len(detected_objects)} objects!")
|
| 184 |
|
| 185 |
# Show annotated image
|
| 186 |
st.markdown("### π― Detection Results")
|
| 187 |
+
st.image(annotated_img, caption="Detected Objects", use_column_width=True)
|
|
|
|
| 188 |
|
| 189 |
# Show detection details
|
| 190 |
st.markdown("### π Detected Objects")
|
| 191 |
+
# Count unique objects
|
| 192 |
+
object_counts = {}
|
| 193 |
+
for obj in detected_objects:
|
| 194 |
+
object_counts[obj] = object_counts.get(obj, 0) + 1
|
| 195 |
+
|
| 196 |
+
for i, (obj_name, count) in enumerate(object_counts.items()):
|
| 197 |
col_a, col_b, col_c = st.columns(3)
|
| 198 |
with col_a:
|
| 199 |
+
st.metric("Object", obj_name)
|
| 200 |
with col_b:
|
| 201 |
+
st.metric("Count", count)
|
| 202 |
with col_c:
|
| 203 |
+
st.metric("ID", f"#{i+1}")
|
| 204 |
|
| 205 |
# AI Explanation
|
| 206 |
if os.getenv("OPENAI_API_KEY"):
|
|
|
|
| 215 |
st.warning("π Add OPENAI_API_KEY in settings for AI explanations")
|
| 216 |
|
| 217 |
else:
|
| 218 |
+
st.warning("β No objects detected in this image.")
|
| 219 |
|
| 220 |
with col2:
|
| 221 |
st.markdown("### π Detection Statistics")
|