Skip to content

Commit

Permalink
fix some bugs (#10)
Browse files Browse the repository at this point in the history
* fix typo

* add missing dependency

* Update __init__.py

* Update hf_utils.py

* fix a bug

* fix a typo

* Update hf_utils.py

* fix typo

* fix a typo

* fix a typo
  • Loading branch information
keremberke authored Jan 13, 2023
1 parent be95615 commit ca76274
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 7 deletions.
3 changes: 2 additions & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
huggingface_hub
fire
ultralytics>=8.0.4
sahi>=0.11.10
sahi>=0.11.10
pandas
2 changes: 1 addition & 1 deletion ultralyticsplus/__init__.py
Original file line number Diff line number Diff line change
@@ -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"
7 changes: 7 additions & 0 deletions ultralyticsplus/file_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
12 changes: 7 additions & 5 deletions ultralyticsplus/hf_utils.py
Original file line number Diff line number Diff line change
@@ -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

Expand Down Expand Up @@ -54,7 +56,7 @@ def generate_model_usage_markdown(
---
<div align="center">
<img width="640" alt="{repo_id}" src="https://huggingface.co/{repo_id}/resolve/main/sample_visuals.jpg">
<img width="640" alt="{repo_id}" src="https://huggingface.co/{repo_id}/resolve/main/thumbnail.jpg">
</div>
### Supported Labels
Expand Down Expand Up @@ -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)

Expand All @@ -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,
Expand Down Expand Up @@ -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,
Expand Down

0 comments on commit ca76274

Please sign in to comment.