Abs6187 commited on
Commit
cc8344a
·
verified ·
1 Parent(s): c000958

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +12 -16
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, conf_threshold):
10
- results = model.predict(source=image, show=False, conf=conf_threshold)
11
  results_img = results[0].plot() # Get the image with bounding boxes/annotations
12
- detected_classes = results[0].names # Get class names
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
- gr.Image(type="pil"), # Input type is image (PIL)
24
- gr.Slider(minimum=0.1, maximum=1.0, step=0.1, default=0.6, label="Confidence Threshold") # Slider for confidence
25
- ],
26
- outputs=[
27
- gr.Image(type="pil"), # Output type is image (PIL)
28
- gr.Textbox(label="Detected Activities") # Output type for detected activities
29
- ],
30
  title="Suspicious Activity Detection with YOLO", # Interface title
31
- description="Upload an image to detect suspicious activities such as Assault, Fighting, Gun incidents, etc.", # Description
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