Spaces:
Runtime error
Runtime error
hugo scheithauer
commited on
Commit
·
86514f9
1
Parent(s):
dec3e92
adding comments
Browse files
app.py
CHANGED
@@ -3,18 +3,28 @@ from huggingface_hub import hf_hub_download
|
|
3 |
from PIL import Image
|
4 |
import yolov5
|
5 |
|
6 |
-
#
|
7 |
model_file = hf_hub_download(repo_id="HugoSchtr/yolov5_datacat", filename="best.pt")
|
8 |
|
9 |
model = yolov5.load(model_file)
|
10 |
|
|
|
11 |
def predict(im, threshold=0.50):
|
|
|
|
|
|
|
|
|
|
|
12 |
# g = (size / max(im.size)) # gain
|
13 |
-
# im = im.resize((int(x * g) for x in im.size), Image.ANTIALIAS)
|
|
|
|
|
14 |
model.conf = threshold
|
15 |
-
|
|
|
16 |
numpy_image = results.render()[0]
|
17 |
output_image = Image.fromarray(numpy_image)
|
|
|
18 |
return output_image
|
19 |
|
20 |
title = "YOLOv5 - Auction sale catalogues layout analysis"
|
|
|
3 |
from PIL import Image
|
4 |
import yolov5
|
5 |
|
6 |
+
# Downloading the model from HuggingFace
|
7 |
model_file = hf_hub_download(repo_id="HugoSchtr/yolov5_datacat", filename="best.pt")
|
8 |
|
9 |
model = yolov5.load(model_file)
|
10 |
|
11 |
+
# Prediction function
|
12 |
def predict(im, threshold=0.50):
|
13 |
+
"""
|
14 |
+
Performs prediction using Datacat YOLOv5 model
|
15 |
+
"""
|
16 |
+
|
17 |
+
# We could resize the image, but the application handles high definition for now
|
18 |
# g = (size / max(im.size)) # gain
|
19 |
+
# im = im.resize((int(x * g) for x in im.size), Image.ANTIALIAS)
|
20 |
+
|
21 |
+
# initializing confidence threshold
|
22 |
model.conf = threshold
|
23 |
+
# inference
|
24 |
+
results = model(im)
|
25 |
numpy_image = results.render()[0]
|
26 |
output_image = Image.fromarray(numpy_image)
|
27 |
+
|
28 |
return output_image
|
29 |
|
30 |
title = "YOLOv5 - Auction sale catalogues layout analysis"
|