""" Gradio APP for Yolov5 medieval registers layout analysis. Date: 20/12/2022 Author: lterriel """ import glob import sys, types import gradio as gr from PIL import Image from huggingface_hub import hf_hub_download # --- HF errors shim (compat with old yolov5 import path) try: import huggingface_hub.errors as hf_errors if 'huggingface_hub.utils' not in sys.modules: sys.modules['huggingface_hub.utils'] = types.ModuleType('huggingface_hub.utils') sys.modules['huggingface_hub.utils._errors'] = hf_errors except Exception: pass import yolov5 # must come after the shim # Add new models here: model_names = [ "lterriel/endp-yolov5x-35e-bs4", ] def load_model(model_name: str) -> str: # download local checkpoint from HF return hf_hub_download(repo_id=model_name, filename="best.pt") def yolo_inference(im, model_name, threshold=0.50): model_path = load_model(model_name) model = yolov5.load(model_path) model.conf = float(threshold) results = model(im) # inference numpy_image = results.render()[0] return Image.fromarray(numpy_image) title = "YOLOv5 - Medieval Register Segmentation" description = """