Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
|
@@ -4,7 +4,7 @@ from cvlib.object_detection import draw_bbox
|
|
| 4 |
import streamlit as st
|
| 5 |
from PIL import Image
|
| 6 |
from collections import Counter
|
| 7 |
-
import
|
| 8 |
|
| 9 |
# Streamlit app title
|
| 10 |
st.set_page_config(page_title="Object Detection App", page_icon="🖼️", layout="centered")
|
|
@@ -25,11 +25,12 @@ uploaded_file = st.file_uploader("Choose an image...", type=["png", "jpg", "jpeg
|
|
| 25 |
def detect_common_objects_skip_progress(image, model='yolov3'):
|
| 26 |
model_config = 'yolov3.cfg' # Path to your downloaded .cfg file
|
| 27 |
model_weights = 'yolov3.weights' # Path to your downloaded .weights file
|
| 28 |
-
|
| 29 |
-
#
|
| 30 |
-
|
| 31 |
-
|
| 32 |
-
|
|
|
|
| 33 |
return box, label, count
|
| 34 |
|
| 35 |
if uploaded_file is not None:
|
|
@@ -38,24 +39,24 @@ if uploaded_file is not None:
|
|
| 38 |
|
| 39 |
# Perform object detection with manually provided paths
|
| 40 |
box, label, count = detect_common_objects_skip_progress(image)
|
| 41 |
-
|
| 42 |
# Draw bounding boxes on the image
|
| 43 |
output_image = draw_bbox(image, box, label, count)
|
| 44 |
-
|
| 45 |
# Step 2: Display image with bounding boxes
|
| 46 |
st.markdown("### Step 2: Detected Objects in the Image")
|
| 47 |
st.image(output_image, channels="BGR", use_column_width=True)
|
| 48 |
-
|
| 49 |
# Step 3: Display the count of detected objects dynamically
|
| 50 |
st.markdown("### Step 3: Detected Objects Count")
|
| 51 |
-
|
| 52 |
# Count each label in the image using Counter
|
| 53 |
label_counts = Counter(label)
|
| 54 |
-
|
| 55 |
# Display counts in a well-formatted table
|
| 56 |
for obj, count in label_counts.items():
|
| 57 |
st.markdown(f"**{obj.capitalize()}s**: {count}")
|
| 58 |
-
|
| 59 |
st.markdown("""
|
| 60 |
---
|
| 61 |
### Tips:
|
|
|
|
| 4 |
import streamlit as st
|
| 5 |
from PIL import Image
|
| 6 |
from collections import Counter
|
| 7 |
+
import cv2 # OpenCV for loading the YOLO model
|
| 8 |
|
| 9 |
# Streamlit app title
|
| 10 |
st.set_page_config(page_title="Object Detection App", page_icon="🖼️", layout="centered")
|
|
|
|
| 25 |
def detect_common_objects_skip_progress(image, model='yolov3'):
|
| 26 |
model_config = 'yolov3.cfg' # Path to your downloaded .cfg file
|
| 27 |
model_weights = 'yolov3.weights' # Path to your downloaded .weights file
|
| 28 |
+
|
| 29 |
+
# Load the YOLO model manually using OpenCV
|
| 30 |
+
net = cv2.dnn.readNet(model_weights, model_config)
|
| 31 |
+
|
| 32 |
+
# Perform object detection using cvlib (cvlib internally uses the loaded model)
|
| 33 |
+
box, label, count = cv.detect_common_objects(image, model='yolov3', net=net)
|
| 34 |
return box, label, count
|
| 35 |
|
| 36 |
if uploaded_file is not None:
|
|
|
|
| 39 |
|
| 40 |
# Perform object detection with manually provided paths
|
| 41 |
box, label, count = detect_common_objects_skip_progress(image)
|
| 42 |
+
|
| 43 |
# Draw bounding boxes on the image
|
| 44 |
output_image = draw_bbox(image, box, label, count)
|
| 45 |
+
|
| 46 |
# Step 2: Display image with bounding boxes
|
| 47 |
st.markdown("### Step 2: Detected Objects in the Image")
|
| 48 |
st.image(output_image, channels="BGR", use_column_width=True)
|
| 49 |
+
|
| 50 |
# Step 3: Display the count of detected objects dynamically
|
| 51 |
st.markdown("### Step 3: Detected Objects Count")
|
| 52 |
+
|
| 53 |
# Count each label in the image using Counter
|
| 54 |
label_counts = Counter(label)
|
| 55 |
+
|
| 56 |
# Display counts in a well-formatted table
|
| 57 |
for obj, count in label_counts.items():
|
| 58 |
st.markdown(f"**{obj.capitalize()}s**: {count}")
|
| 59 |
+
|
| 60 |
st.markdown("""
|
| 61 |
---
|
| 62 |
### Tips:
|