Navada25 commited on
Commit
e8191b3
Β·
verified Β·
1 Parent(s): 526003b

Fix: Corrected detect_objects function call and return handling

Browse files
Files changed (1) hide show
  1. app.py +13 -12
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
- results = detect_objects(image, confidence_threshold=confidence)
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
- if 'annotated_image' in results:
191
- st.image(results['annotated_image'], caption="Detected Objects", use_column_width=True)
192
 
193
  # Show detection details
194
  st.markdown("### πŸ“‹ Detected Objects")
195
- for i, detection in enumerate(results['detections']):
 
 
 
 
 
196
  col_a, col_b, col_c = st.columns(3)
197
  with col_a:
198
- st.metric("Object", detection['class'])
199
  with col_b:
200
- st.metric("Confidence", f"{detection['confidence']:.2%}")
201
  with col_c:
202
- st.metric("Count", f"#{i+1}")
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. Try adjusting the confidence threshold.")
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")