Abs6187 commited on
Commit
7f292e1
·
verified ·
1 Parent(s): e7743ab

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +11 -7
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 a function to predict and return the result
8
  def predict_suspicious_activity(image):
9
- results = model.predict(source=image, show=True, conf=0.6)
10
- return results.pandas().xywh[0].to_dict() # Adjust as per your model output structure
 
11
 
12
  # Create Gradio interface
13
  interface = gr.Interface(
14
- fn=predict_suspicious_activity,
15
- inputs=gr.inputs.Image(type="pil"), # Input type for uploading images
16
- outputs="json" # Output type (you can adjust this based on your needs)
 
 
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)