提供程序访问DALL·E 2 API的库
项目描述
pydalle:Python的DALL·E 2 API包装器
此库提供对DALL·E 2 API的基本程序访问。
此库的目的是为研究人员提供一种简单地将DALL·E 2的结果布局到jupyter笔记本或类似工具中的方法。
pydalle有两种主要的使用模式
pydalle.Dalle
:这是库的主要类。它提供了一个用户友好的界面来访问DALL·E 2 API。 更多信息。pydalle.imperative.api.labs
:此模块提供了一组可以用于与DALL·E 2 API交互的底层函数。 更多信息。
安装
安装所有依赖项
pip install pydalle[all] # Install all dependencies, recommended for most users
选择您需要的依赖项
pip install pydalle # Just install the library with no optional dependencies
pip install pydalle[sync] # Also installs requests (for synchronous networking)
pip install pydalle[async] # Also installs aiohttp and aiofiles (required for async networking / file handling)
pip install pydalle[images] # Also installs Pillow and numpy (required for help with image processing)
技巧
-
通过注册 DALL·E 2等待列表 获取访问权限。
-
请注意,此库使您轻松花费金钱/DALL·E 2积分。
入门
安装pydalle后,您可以通过导入它并创建一个 Dalle
对象来开始使用它。您可以在 Dalle 类 上找到所有可用方法。
import os
from pydalle import Dalle
OPENAI_USERNAME = os.environ.get('OPENAI_USERNAME')
OPENAI_PASSWORD = os.environ.get('OPENAI_PASSWORD')
def main():
client = Dalle(OPENAI_USERNAME, OPENAI_PASSWORD)
print(f"Client created. {client.get_credit_summary().aggregate_credits} credits remaining...")
tasks = client.get_tasks(limit=5)
print(f"{len(tasks)} tasks found...")
print("Attempting to download a generation of the first task and show off some built-in helpers...")
if tasks and tasks[0].generations:
example = tasks[0].generations[0].download()
example.to_pil().show() # Convert the image to a PIL image and show it
example.to_pil_masked(x1=0.5, y1=0, x2=1, y2=1).show() # Show a version with left side transparent (for edits)
example.to_pil_padded(0.5).show() # Show w/ 50% padding around the image, centered at (50%, 50%)
example.to_pil_padded(0.4, cx=0.25, cy=0.25).show() # Show w/ 40% padding, centered at (25%, 25%)
print("Attempting to do a text2im task...")
completed_text2im_task = client.text2im("A cute cat")
for image in completed_text2im_task.download():
image.to_pil().show()
print("Attempting to create variations task on the first cat...")
first_generation = completed_text2im_task.generations[0]
completed_variation_task = first_generation.variations()
first_variation = completed_variation_task.generations[0]
first_image = first_variation.download()
first_image.to_pil().show()
print("Attempting to create inpainting task and showing the mask...")
# Make the right-side of the image transparent
mask = first_image.to_pil_masked(x1=0.5, y1=0, x2=1, y2=1)
mask.show("inpainting mask")
completed_inpainting_task = first_generation.inpainting("A cute cat, with a dark side", mask)
for image in completed_inpainting_task.download():
image.to_pil().show()
if __name__ == '__main__':
main()
关于等效的异步代码示例,请参阅 examples/dev_client_async.py。
有关低级API示例以及在笔记本中使用这些示例的说明,请参阅 examples/low_level 目录。
项目详情
下载文件
下载适用于您平台的文件。如果您不确定选择哪个,请了解有关 安装包 的更多信息。
源分布
pydalle-0.2.0.tar.gz (25.8 kB 查看哈希值)
构建分布
pydalle-0.2.0-py3-none-any.whl (31.8 kB 查看哈希值)
关闭
pydalle-0.2.0.tar.gz 的哈希值
算法 | 哈希摘要 | |
---|---|---|
SHA256 | ef63a0ada8e9d44d8cdecefaee7efd89902ad92802e708fdcc838733de3b4d63 |
|
MD5 | bd03a2665104c1fc85b15a6c8c69e394 |
|
BLAKE2b-256 | f9840e1eddda7bac4380386734b00206cbe917d87faca9c124f77c60ebb6a695 |
关闭
pydalle-0.2.0-py3-none-any.whl 的哈希值
算法 | 哈希摘要 | |
---|---|---|
SHA256 | d3c2b80e0bffb787495e95e7c3f808c1a2dabf052af662ee7955a20068fe21d8 |
|
MD5 | 4f934c14813799b24967cc39aab25e1b |
|
BLAKE2b-256 | ebd3b1dfae2f9416be887440ef7d630a0a8310e47ad2871f62d8dfead0d14f12 |