35-----图片胜一千字

截至 2022 年 6 月,最热门的🔥型号之一是DALL-E mini。如此处、此处和此处所示,有许多使用此模型的项目和示例。甚至有主流新闻文章报道过这种模式。

本文介绍了构建网页摘要然后生成该摘要图像的工作流程。虽然文本到图像模型有许多潜在用例,但此示例侧重于展示工作流程的强大功能,并提供有关 DALL-E mini 如何“看”世界的有趣见解。

安装依赖
安装txtai和所有依赖项。

DALL-E 迷你模型和代码的所有功劳都归功于https://github.com/borisdayma/dalle-mini和https://github.com/kuprel/min-dalle。
pip install txtai tika min-dalle ipyplot
构建 DALL-E 管道
让我们首先构建一个使用 DALL-E mini 生成图像的 txtai 管道。
from min_dalle import MinDalle

from txtai.pipeline import Pipeline

class Dalle(Pipeline):
def init(self):
self.model = MinDalle(is_mega=False, is_verbose=False)

def call(self, texts, seed, prefix):
results = []
for text in texts:
text = prefix + text
results.append(self.model.generate_image(text, seed))

return results

构建 DALL-E 工作流程
接下来我们将定义一个 txtai 工作流作为 YAML。此工作流提取指定 URL 处的文本,构建摘要,然后为摘要文本生成图像。

此工作流可以从 Python 运行,如下所示或作为API 服务运行。
from txtai.app import Application

app = Application(“”"
main.Dalle:
summary:
path: sshleifer/distilbart-cnn-12-6
textractor:
join: true
lines: false
minlength: 100
paragraphs: true
sentences: false
workflow:
draw:
tasks:
- action: textractor
task: url
- action: summary
args: [0, 60, 0]
- action: main.Dalle
args: [1024, "Illustration of “]
“””)
生成网页摘要图像
现在工作流程已经启动,让我们生成一些图像!以下示例为一组维基百科文章生成图像。尝试一下文章、食谱或任何其他描述性网页。

使用此 url 为随机维基百科页面生成图像也很有趣:https://en.wikipedia.org/wiki/Special:Random
import ipyplot

Build list of Wikipedia article URLs

captions = [“Catholic Church”, “Magic Kingdom”, “Epcot”, “Mountain”, “Tundra”, “War of 1812”, “Chinese Cuisine”, “Indian Cuisine”, “Italian Cuisine”,
“Romanian cuisine”, “Football”, “Artificial Intelligence”, “Galaxy”, “Fjord”, “Island”]
urls = [f"https://en.wikipedia.org/wiki/{url.replace(’ ', ‘_’)}" for url in captions]

Run workflow to generate images with DALL-E mini

images = list(app.workflow(“draw”, urls))

Plot images

ipyplot.plot_images(images, captions, img_width=256)
在这里插入图片描述
包起来
本文通过一个示例介绍了如何构建 txtai 工作流来生成网页摘要图像。DALL-E mini 是一款引人入胜的模型,“了解”该模型的工作原理非常有趣。自己试一试!

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

Q shen

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值