Skip to content

Commit

Permalink
loadimg from 🤗
Browse files Browse the repository at this point in the history
  • Loading branch information
not-lain committed Apr 7, 2024
1 parent 9642629 commit 087a220
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 2 deletions.
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

setup(
name="loadimg",
version="0.1.1",
version="0.1.2",
description="a python package for loading images",
long_description=pathlib.Path("README.md").read_text(encoding="utf-8"),
long_description_content_type="text/markdown",
Expand Down
4 changes: 3 additions & 1 deletion src/loadimg/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,12 @@ def download_image(url: str):
try:
if "github" in url and "raw=true" not in url:
url += "?raw=true"
if "drive" in url and "uc?id=" not in url:
elif "drive" in url and "uc?id=" not in url:
if "/view" in url or url.endswith("/"):
url = "/".join(url.split("/")[:-1])
url = "https://drive.google.com/uc?id=" + url.split("/")[-1]
elif "hf.co" or "huggingface.co" in url :
url = url.replace("/blob/","/resolve")
response = requests.get(url, timeout=5) # Timeout set to 5 seconds
response.raise_for_status() # Raise an exception for HTTP errors
return Image.open(BytesIO(response.content))
Expand Down

0 comments on commit 087a220

Please sign in to comment.