Sign_detection / app.py
Shreyas14047's picture
Create app.py
7a4ff2c verified
raw
history blame contribute delete
926 Bytes
#!pip install ultralytics supervision huggingface_hub opencv-python
import cv2
import os
import supervision as sv
from huggingface_hub import hf_hub_download
from ultralytics import YOLO
from huggingface_hub import login
login(token=os.getenv("HF_TOKEN"))
#download the model
model_path = hf_hub_download(
repo_id="tech4humans/yolov8s-signature-detector",
filename="yolov8s.pt"
)
#load model
model = YOLO(model_path)
# choose your image manually
from google.colab import files
uploaded = files.upload()
# gets the uploaded filename
image_path = list(uploaded.keys())[0]
image = cv2.imread(image_path)
#inference part
results = model(image_path)
detections = sv.Detections.from_ultralytics(results[0])
box_annotator = sv.BoxAnnotator()
annotated_image = box_annotator.annotate(scene=image, detections=detections)
from google.colab.patches import cv2_imshow
# Show result image
cv2_imshow(annotated_image)