import gradio as gr from ultralytics import YOLO import torch model_id = "mosesb/best-comic-panel-detection" model = YOLO("best.pt") def detect_panels(pil_image, conf_threshold, iou_threshold): """ Takes a PIL image and thresholds, runs YOLOv12 object detection, and returns the annotated image with bounding boxes. """ # Run inference on the image with the specified thresholds results = model.predict(pil_image, conf=conf_threshold, iou=iou_threshold, verbose=False) annotated_image = results[0].plot() # Gradio's gr.Image component expects an RGB image. The .plot() method # returns a BGR image, so we convert it. annotated_image_rgb = annotated_image[..., ::-1] return annotated_image_rgb # --- Gradio Interface --- title = "YOLOv12 Comic Panel Detection" description = """ This demo showcases a **YOLOv12 object detection model** that has been fine-tuned to detect panels in comic book pages. Upload an image of a comic page, and the model will draw bounding boxes around each detected panel. This can be a useful first step for downstream tasks like Optical Character Recognition (OCR) or character analysis within comics. """ article = f"""
Model loaded from {model_id}
For more details on the training process, check out the project repository: Comic Boundary Detection
If you like this demo, consider leaving a star on the Github repo or a like on the Hugging Face model. It helps me know people are interested and motivates further development.