diff --git a/requirements.txt b/requirements.txt index c7af270..4d25110 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,4 +1,5 @@ huggingface_hub fire ultralytics>=8.0.4 -sahi>=0.11.10 \ No newline at end of file +sahi>=0.11.10 +pandas diff --git a/ultralyticsplus/__init__.py b/ultralyticsplus/__init__.py index 137e6b4..a2856d8 100644 --- a/ultralyticsplus/__init__.py +++ b/ultralyticsplus/__init__.py @@ -1,4 +1,4 @@ from .hf_utils import push_to_hfhub, download_from_hub from .ultralytics_utils import YOLO, render_predictions -__version__ = "0.0.5" +__version__ = "0.0.6" diff --git a/ultralyticsplus/file_utils.py b/ultralyticsplus/file_utils.py index cfb289d..3866f66 100644 --- a/ultralyticsplus/file_utils.py +++ b/ultralyticsplus/file_utils.py @@ -38,6 +38,13 @@ def add_text_to_image( # Get the width and height of the text text_width = bbox[2] - bbox[0] text_height = bbox[3] - bbox[1] + + # update font size + text_font = int(860 / text_width * text_font) + font = ImageFont.truetype("OpenSans-Bold.ttf", text_font) + bbox = draw.textbbox((0, 0), text, font=font) + text_width = bbox[2] - bbox[0] + text_height = bbox[3] - bbox[1] # Define the coordinates of the smaller rounded rectangle box_margin = 20 diff --git a/ultralyticsplus/hf_utils.py b/ultralyticsplus/hf_utils.py index 183100a..aaf8827 100644 --- a/ultralyticsplus/hf_utils.py +++ b/ultralyticsplus/hf_utils.py @@ -1,6 +1,8 @@ import logging import os from pathlib import Path +import pandas as pd +from PIL import Image from ultralyticsplus.file_utils import add_text_to_image @@ -54,7 +56,7 @@ def generate_model_usage_markdown( ---
- {repo_id} + {repo_id}
### Supported Labels @@ -106,10 +108,10 @@ def generate_thumbnail(image_path, repo_id, task="object-detection"): """ thumbnail_text = repo_id.split("/")[-1] texts = thumbnail_text.split("-") - for text in texts: + for ind, text in enumerate(texts): if "yolo" not in text.lower(): text = text.title() - text.replace("yolo", "YOLO") + texts[ind] = text.replace("yolo", "YOLO") thumbnail_text = " ".join(texts) @@ -124,7 +126,7 @@ def generate_thumbnail(image_path, repo_id, task="object-detection"): image = add_text_to_image( text=thumbnail_text, - image_path=image_path, + pil_image=Image.open(image_path), brightness=0.60, text_font=65, crop_margin=None, @@ -162,7 +164,7 @@ def push_model_card_to_hfhub( thumbnail_path = generate_thumbnail(sample_visual_path, repo_id=repo_id, task=task) upload_file( repo_id=repo_id, - path_or_fileobj=thumbnail_path, + path_or_fileobj=str(thumbnail_path), path_in_repo="thumbnail.jpg", commit_message="upload sample visuals", token=hf_token,