Spaces:
Build error
Build error
Create app.py
Browse files
app.py
ADDED
|
@@ -0,0 +1,39 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#!pip install ultralytics supervision huggingface_hub opencv-python
|
| 2 |
+
|
| 3 |
+
import cv2
|
| 4 |
+
import os
|
| 5 |
+
import supervision as sv
|
| 6 |
+
from huggingface_hub import hf_hub_download
|
| 7 |
+
from ultralytics import YOLO
|
| 8 |
+
from huggingface_hub import login
|
| 9 |
+
|
| 10 |
+
login(token=os.getenv("HF_TOKEN"))
|
| 11 |
+
|
| 12 |
+
#download the model
|
| 13 |
+
model_path = hf_hub_download(
|
| 14 |
+
repo_id="tech4humans/yolov8s-signature-detector",
|
| 15 |
+
filename="yolov8s.pt"
|
| 16 |
+
)
|
| 17 |
+
|
| 18 |
+
#load model
|
| 19 |
+
model = YOLO(model_path)
|
| 20 |
+
|
| 21 |
+
# choose your image manually
|
| 22 |
+
from google.colab import files
|
| 23 |
+
uploaded = files.upload()
|
| 24 |
+
|
| 25 |
+
# gets the uploaded filename
|
| 26 |
+
image_path = list(uploaded.keys())[0]
|
| 27 |
+
image = cv2.imread(image_path)
|
| 28 |
+
|
| 29 |
+
#inference part
|
| 30 |
+
results = model(image_path)
|
| 31 |
+
detections = sv.Detections.from_ultralytics(results[0])
|
| 32 |
+
box_annotator = sv.BoxAnnotator()
|
| 33 |
+
annotated_image = box_annotator.annotate(scene=image, detections=detections)
|
| 34 |
+
from google.colab.patches import cv2_imshow
|
| 35 |
+
|
| 36 |
+
# Show result image
|
| 37 |
+
cv2_imshow(annotated_image)
|
| 38 |
+
|
| 39 |
+
|