DataCat_Yolov5 / app.py
hugo scheithauer
downloading model from the hub + new examples
aae0967
raw
history blame
1.62 kB
import gradio as gr
from huggingface_hub import hf_hub_download
from PIL import Image
import yolov5
# Model
model_file = hf_hub_download(repo_id="HugoSchtr/yolov5_datacat", filename="best.pt")
model = yolov5.load(model_file)
def predict(im, threshold=0.50):
# g = (size / max(im.size)) # gain
# im = im.resize((int(x * g) for x in im.size), Image.ANTIALIAS) # resize
model.conf = threshold
results = model(im) # inference
numpy_image = results.render()[0]
output_image = Image.fromarray(numpy_image)
return output_image
title = "YOLOv5 - Auction sale catalogues layout analysis"
description = "<p style='text-align: center'>YOLOv5 Gradio demo for auction sales catalogues layout analysis. Detecting titles and catalogues entries.</p>"
article = "<p style='text-align: center'>YOLOv5 source code : <a href='https://github.com/ultralytics/yolov5'>Source code</a> | <a href='https://pytorch.org/hub/ultralytics_yolov5'>PyTorch Hub</a></p>"
examples = [['./img_examples/12148-bpt6k1240127r.pdf_page_20.png', 0.50],
['./img_examples/12148-bpt6k1240127r.pdf_page_21.png', 0.50],
['./img_examples/12148-bpt6k1240127r.pdf_page_27.png', 0.50]]
demo=gr.Interface(fn=predict,
inputs=[gr.Image(type="pil", label="document image"), gr.Slider(maximum=1, step=0.01, value=0.50)],
outputs=gr.Image(type="pil", label="annotated document").style(height=700),
title=title,
description=description,
article=article,
examples=examples,
theme="huggingface")
if __name__ == "__main__":
demo.launch(debug=True)