Skip to main content

一个用于从Hugging Face数据集下载图片的Python包

Project description

HFPics

一个简单的Python包,用于从Hugging Face数据集下载图片。

安装

pip install hfpics

使用方法

from hfpics import HfPics

# 使用默认配置
hf = HfPics()

# 或使用自定义配置
hf = HfPics(
    repo="picollect/a_1024",  # 自定义数据集仓库
    cache_dir="/custom/path"   # 自定义缓存目录
)

# 下载图片并获取路径
image_path = hf.pic(11112)
print(f"图片保存在: {image_path}")

# 直接获取图片内容
image_content = hf.pic(11112, return_type="content")

功能特点

  • 支持从Hugging Face数据集下载图片
  • 自动缓存已下载的图片
  • 支持返回图片路径或二进制内容
  • 支持.jpg和.webp格式
  • 支持自定义缓存目录

API文档

HfPics类

HfPics(repo: str = "picollect/a_1024", cache_dir: str = "~/.cache/hf_pics")

参数:

  • repo: Hugging Face数据集仓库名称,默认"picollect/a_1024",为a站数据集
  • cache_dir: 缓存目录路径,默认"~/.cache/hf_pics"

pic方法

pic(id: int, return_type: Literal["path", "content"] = "path") -> Union[str, bytes, None]

参数:

  • id: 图片ID(整数)
  • return_type: 返回类型
    • "path": 返回图片文件路径(默认)
    • "content": 返回图片二进制内容

返回值:

  • 当 return_type="path" 时返回字符串路径
  • 当 return_type="content" 时返回字节内容
  • 如果图片不存在返回 None

异常处理

try:
    image = hf.pic(11112)
except ValueError as e:
    print(f"参数错误: {e}")
except Exception as e:
    print(f"下载失败: {e}")

许可证

MIT License

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

hfpics-0.1.0.tar.gz (5.3 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

hfpics-0.1.0-py3-none-any.whl (4.5 kB view details)

Uploaded Python 3

File details

Details for the file hfpics-0.1.0.tar.gz.

File metadata

  • Download URL: hfpics-0.1.0.tar.gz
  • Upload date:
  • Size: 5.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.0.1 CPython/3.9.21

File hashes

Hashes for hfpics-0.1.0.tar.gz
Algorithm Hash digest
SHA256 7fd802bd610ae854d34e806646329424b133a5a9bd096ecb81fc7b7f4a1111fb
MD5 7cdf6fbfd99ac7e6620e4b2c88b14395
BLAKE2b-256 7e5d2a77f5b3f684a8eb8e447521c21245664855b7d03e63a9241d2b8a82fc12

See more details on using hashes here.

File details

Details for the file hfpics-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: hfpics-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 4.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.0.1 CPython/3.9.21

File hashes

Hashes for hfpics-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 b6ad0855e22169e04c7a8f56071b71c5540537424c85ecbca81e1eb8e461e2aa
MD5 02ef2e9dbd8ec27320f981a43ad3dffd
BLAKE2b-256 0fad2c1fbfe5ba643b547b6939ae1d18fe20b92513faebcf06fd0dfa4dd093f7

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page