Update app.py
Browse files
app.py
CHANGED
@@ -6,29 +6,25 @@ from PIL import Image
|
|
6 |
model = YOLO("Suspicious_Activities_nano.pt")
|
7 |
|
8 |
# Define the prediction function
|
9 |
-
def predict_suspicious_activity(image
|
10 |
-
results = model.predict(source=image, show=False, conf=
|
11 |
results_img = results[0].plot() # Get the image with bounding boxes/annotations
|
12 |
-
|
13 |
|
14 |
-
# Create a string of detected classes
|
15 |
-
detected_text = ', '.join(set(detected_classes)) if detected_classes else "No suspicious activities detected."
|
16 |
-
|
17 |
-
return Image.fromarray(results_img), detected_text # Return both image and detected classes
|
18 |
|
19 |
# Create Gradio interface
|
20 |
interface = gr.Interface(
|
21 |
fn=predict_suspicious_activity, # Function to run on input
|
22 |
-
inputs=
|
23 |
-
|
24 |
-
|
25 |
-
|
26 |
-
|
27 |
-
|
28 |
-
|
29 |
-
|
30 |
title="Suspicious Activity Detection with YOLO", # Interface title
|
31 |
-
description="Upload an image to detect suspicious activities
|
32 |
)
|
33 |
|
34 |
# Launch the interface
|
|
|
6 |
model = YOLO("Suspicious_Activities_nano.pt")
|
7 |
|
8 |
# Define the prediction function
|
9 |
+
def predict_suspicious_activity(image):
|
10 |
+
results = model.predict(source=image, show=False, conf=0.6)
|
11 |
results_img = results[0].plot() # Get the image with bounding boxes/annotations
|
12 |
+
return Image.fromarray(results_img) # Get class names
|
13 |
|
|
|
|
|
|
|
|
|
14 |
|
15 |
# Create Gradio interface
|
16 |
interface = gr.Interface(
|
17 |
fn=predict_suspicious_activity, # Function to run on input
|
18 |
+
inputs=gr.Image(type="pil"), # Input type is image (PIL)
|
19 |
+
outputs=gr.Image(type="pil"), # Output type is image (PIL)
|
20 |
+
|
21 |
+
|
22 |
+
|
23 |
+
|
24 |
+
|
25 |
+
|
26 |
title="Suspicious Activity Detection with YOLO", # Interface title
|
27 |
+
description="Upload an image to detect suspicious activities.", # Description
|
28 |
)
|
29 |
|
30 |
# Launch the interface
|