Update app.py
Browse files
app.py
CHANGED
|
@@ -1,20 +1,24 @@
|
|
| 1 |
import gradio as gr
|
| 2 |
from ultralytics import YOLO
|
|
|
|
| 3 |
|
| 4 |
# Load YOLO model
|
| 5 |
model = YOLO("Suspicious_Activities_nano.pt")
|
| 6 |
|
| 7 |
-
# Define
|
| 8 |
def predict_suspicious_activity(image):
|
| 9 |
-
results = model.predict(source=image, show=
|
| 10 |
-
|
|
|
|
| 11 |
|
| 12 |
# Create Gradio interface
|
| 13 |
interface = gr.Interface(
|
| 14 |
-
fn=predict_suspicious_activity,
|
| 15 |
-
inputs=gr.
|
| 16 |
-
outputs="
|
|
|
|
|
|
|
| 17 |
)
|
| 18 |
|
| 19 |
# Launch the interface
|
| 20 |
-
interface.launch()
|
|
|
|
| 1 |
import gradio as gr
|
| 2 |
from ultralytics import YOLO
|
| 3 |
+
from PIL import Image
|
| 4 |
|
| 5 |
# Load YOLO model
|
| 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) # Convert NumPy array to PIL Image for Gradio
|
| 13 |
|
| 14 |
# Create Gradio interface
|
| 15 |
interface = gr.Interface(
|
| 16 |
+
fn=predict_suspicious_activity, # Function to run on input
|
| 17 |
+
inputs=gr.Image(type="pil"), # Input type is image (PIL)
|
| 18 |
+
outputs=gr.Image(type="pil"), # Output type is image (PIL)
|
| 19 |
+
title="Suspicious Activity Detection with YOLO", # Interface title
|
| 20 |
+
description="Upload an image to detect suspicious activities.", # Description
|
| 21 |
)
|
| 22 |
|
| 23 |
# Launch the interface
|
| 24 |
+
interface.launch(share=True)
|