keffy commited on
Commit
991bd10
1 Parent(s): 74350e4

Upload 4 files

Browse files
Files changed (4) hide show
  1. .gitignore +8 -0
  2. app.py +36 -0
  3. requirements.txt +12 -0
  4. yolov8n.pt +3 -0
.gitignore ADDED
@@ -0,0 +1,8 @@
 
 
 
 
 
 
 
 
 
1
+ flaggedd/
2
+ *.py
3
+ *.png
4
+ *.mp4
5
+ *.mkv
6
+ graadio_cached_examples/
7
+
8
+
app.py ADDED
@@ -0,0 +1,36 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ import cv2
3
+ import numpy as np
4
+ from ultralytics import YOLO
5
+
6
+ # Load the YOLOv8 model
7
+ model = YOLO("yolov8n.pt") # Ensure this file is in the same directory as app.py on Hugging Face
8
+
9
+ # Define the inference function
10
+ def predict(image):
11
+ # Convert the input image from RGB to BGR (OpenCV format)
12
+ image_bgr = cv2.cvtColor(image, cv2.COLOR_RGB2BGR)
13
+
14
+ # Run the model on the input image
15
+ results = model(image_bgr)
16
+
17
+ # Extract the result image with detections
18
+ annotated_image = results[0].plot() # Returns a BGR image with annotations
19
+
20
+ # Convert the image back to RGB for displaying in Gradio
21
+ annotated_image_rgb = cv2.cvtColor(annotated_image, cv2.COLOR_BGR2RGB)
22
+
23
+ return annotated_image_rgb
24
+
25
+ # Define the Gradio interface
26
+ interface = gr.Interface(
27
+ fn=predict,
28
+ inputs=gr.Image(type="numpy", label="Upload an Image"),
29
+ outputs=gr.Image(type="numpy", label="Detected Objects"),
30
+ title="YOLOv8 Object Detection",
31
+ description="Upload an image to detect objects with YOLOv8 model."
32
+ )
33
+
34
+ # Launch the app
35
+ if __name__ == "__main__":
36
+ interface.launch()
requirements.txt ADDED
@@ -0,0 +1,12 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ torch==1.13.1+cu118 # Ensure compatibility with your GPU and cu118
2
+ torchvision==0.14.1+cu118 # Ensure compatibility with the specified torch version
3
+ ultralytics # For YOLOv8 models
4
+ transformers # For Hugging Face model interfacing
5
+ huggingface_hub # For Hugging Face model uploading and management
6
+ pandas # For data manipulation
7
+ numpy # For numerical operations
8
+ opencv-python-headless # For YOLOv8 image processing
9
+ scipy # For scientific computations
10
+ requests # For handling HTTP requests
11
+ gradio
12
+ Pillow
yolov8n.pt ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:f59b3d833e2ff32e194b5bb8e08d211dc7c5bdf144b90d2c8412c47ccfc83b36
3
+ size 6549796