★★★ 本文源自AI Studio社区精品项目,【点击此处】查看更多精品内容 >>>


新年到,福气到,是时候给自己换一个福气满满兔兔头像啦!

兔年好运到,好事来得早!朋友微微笑,喜庆围你绕!花儿对你开,鸟儿向你叫。生活美满又如意!喜庆!喜庆!一生平安如意!

准备好迎接新春的到来了吗?你是否还在为找不到自己喜欢的新年头像而烦恼吗?还在为集五福而每天扫一扫吗?如果你看到此处,我想这些通通都不是问题。准备好了吗,现在一步一步教你生成专属于自己的兔年头像和各种各样的福,让你兔年心情愉悦,在集福的路上顺顺利利。

本项目将采用 ERNIE-ViLG AI 作画大模型 生成专属于你的兔年头像和五福图像,准备好了吗?

First pip install wenxin-api

# 可以通过"pip install wenxin-api"命令安装
!pip install wenxin-api

Second 调用wenxin_api以及填写text_prompt和style

想要生成自己的专属兔年头像就快快动手吧,机会不多,希望大家都可以拥有不一样的头像和拥有不一样的心情!

# 你的text_prompt用逗号连接词语效果更佳
text_prompt = "吉祥兔年,新春快乐,喜庆,福气满满,微信头像"

# -*- coding: utf-8 -*
import wenxin_api 
from wenxin_api.tasks.text_to_image import TextToImage
wenxin_api.ak = "2j5C55NjoITZi1hpOZDt8cKb3H2WV6Wn"
wenxin_api.sk = "FNGbMjtrTyzzMvDhSwFGQQm2vn8qO0uy"

#style可选
# 古风
# 二次元
# 油画
# 水彩画
# 卡通画
# 蒸汽波艺术
# 浮世绘
# low poly
# 赛博朋克
# 写实风格

input_dict = {
    "text": text_prompt,
    "style": "卡通画"
}
rst = TextToImage.create(**input_dict)

print(rst)
2023-01-13 11:06:14,103 - model is painting now!, taskId: 12834917, waiting: 2m
2023-01-13 11:06:34,542 - model is painting now!, taskId: 12834917, waiting: 30s
{'imgUrls': ['https://wenxin.baidu.com/younger/file/ERNIE-ViLG/fb3c5bf11c253ecdb8d93735d7fa2035a2', 'https://wenxin.baidu.com/younger/file/ERNIE-ViLG/fb3c5bf11c253ecdb8d93735d7fa20355q', 'https://wenxin.baidu.com/younger/file/ERNIE-ViLG/fb3c5bf11c253ecdb8d93735d7fa2035ex', 'https://wenxin.baidu.com/younger/file/ERNIE-ViLG/fb3c5bf11c253ecdb8d93735d7fa203530', 'https://wenxin.baidu.com/younger/file/ERNIE-ViLG/fb3c5bf11c253ecdb8d93735d7fa2035i4', 'https://wenxin.baidu.com/younger/file/ERNIE-ViLG/fb3c5bf11c253ecdb8d93735d7fa2035v9']}
#查看自己生成的
import requests
import os
from PIL import Image
import matplotlib.pyplot as plt
%matplotlib inline

# 生成存图的目录
def init_mkdir():
    data_path = 'output-img'
    if not os.path.exists(data_path): # 判断文件夹是否存在
        os.makedirs(data_path) # 不存在则新建文件夹

init_mkdir()

# 展示生成的图片并保存
for i in rst['imgUrls']:
    #使用requests直接get 下载图片使用
    r = requests.get(i)
    ii = i.split('/')[-1]+'.png'
    out_ii = 'output-img/' + ii
    with open(out_ii, 'wb') as f:
        f.write(r.content)
    f.close()
    img_ = Image.open(out_ii)
    plt.show()
    plt.imshow(img_)

在这里插入图片描述

在这里插入图片描述

在这里插入图片描述

在这里插入图片描述

在这里插入图片描述

在这里插入图片描述

text_prompt = "福字"

# -*- coding: utf-8 -*
import wenxin_api 
from wenxin_api.tasks.text_to_image import TextToImage
wenxin_api.ak = "2j5C55NjoITZi1hpOZDt8cKb3H2WV6Wn"
wenxin_api.sk = "FNGbMjtrTyzzMvDhSwFGQQm2vn8qO0uy"

#style可选
# 古风
# 二次元
# 油画
# 水彩画
# 卡通画
# 蒸汽波艺术
# 浮世绘
# low poly
# 赛博朋克
# 写实风格

input_dict = {
    "text": text_prompt,
    "style": "水彩画"
}
rst = TextToImage.create(**input_dict)

print(rst)
2023-01-13 11:29:59,620 - model is painting now!, taskId: 12835671, waiting: 4m
2023-01-13 11:30:20,033 - model is painting now!, taskId: 12835671, waiting: 30s
{'imgUrls': ['https://wenxin.baidu.com/younger/file/ERNIE-ViLG/1e78b9a38192bb8a58ee11e2725b772ev9', 'https://wenxin.baidu.com/younger/file/ERNIE-ViLG/1e78b9a38192bb8a58ee11e2725b772e30', 'https://wenxin.baidu.com/younger/file/ERNIE-ViLG/1e78b9a38192bb8a58ee11e2725b772ea2', 'https://wenxin.baidu.com/younger/file/ERNIE-ViLG/1e78b9a38192bb8a58ee11e2725b772ei4', 'https://wenxin.baidu.com/younger/file/ERNIE-ViLG/1e78b9a38192bb8a58ee11e2725b772eex', 'https://wenxin.baidu.com/younger/file/ERNIE-ViLG/1e78b9a38192bb8a58ee11e2725b772e5q']}
#查看自己生成的
import requests
import os
from PIL import Image
import matplotlib.pyplot as plt
%matplotlib inline

# 生成存图的目录
def init_mkdir():
    data_path = 'output-img'
    if not os.path.exists(data_path): # 判断文件夹是否存在
        os.makedirs(data_path) # 不存在则新建文件夹

init_mkdir()

# 展示生成的图片并保存
for i in rst['imgUrls']:
    #使用requests直接get 下载图片使用
    r = requests.get(i)
    ii = i.split('/')[-1]+'.png'
    out_ii = 'output-img/' + ii
    with open(out_ii, 'wb') as f:
        f.write(r.content)
    f.close()
    img_ = Image.open(out_ii)
    plt.show()
ge.open(out_ii)
    plt.show()
    plt.imshow(img_)

在这里插入图片描述

在这里插入图片描述

在这里插入图片描述

在这里插入图片描述

在这里插入图片描述

在这里插入图片描述

展示:

兔年新年走隆运,祥瑞如意万事顺,幸福美满乐畅怀,喜色盈门快乐多,金银财宝数不尽,财气亨通福相随,祝朋友新年快乐!

请点击此处查看本环境基本用法.

Please click here for more detailed instructions.

Logo

学大模型,用大模型上飞桨星河社区!每天8点V100G算力免费领!免费领取ERNIE 4.0 100w Token >>>

更多推荐