一、使用文心大模型制作《十五的月亮》MV
在文心大模型ERNIE-ViLG文生图模型地址:wenxin.baidu.com/moduleApi/e… 能力很强,最近一段时间,各式各样的创意层出不穷,看的我是心花怒放,恰好中秋快到了,自己也打算做一个。
文心大模型制作MV《十五的月亮》_哔哩哔哩_bilibiliwww.bilibili.com/video/BV1PY…
二、制作步骤
1.ak和sk申请
这一步主要就是获取官方的ak和sk 登录文心大模型官网后,在顶部选择
右上角“创建API key”,记住这两个key,在之后会用到。当然,你也不要和别人分享你的key,好好保存。
2.编辑Promot
以歌词为基准,进行描述性修改
三、运行项目
1.fork项目
直接fork磊哥哥项目,即可
2.添加风格描述
可以参考 文心大模型-产业级知识增强大模型Promot指南,如比较喜欢像素艺术,可以在生成时,text后添加像素艺术即可。有多重艺术风格可选:
promot修改:
for index, txt in enumerate(self.lrcs): print(index, txt) if index >= startindex: textlist = txt.split("@:") if len(textlist) > 1 and textlist[-1] is not '': txt = textlist[-1] txt = txt.replace("\n", "") txt = txt + "中国风,像素艺术" print("real text:", txt) idict = self.getImageDict(txt) self.readAndSave(idict, text=txt, ind=index)
3.参考指南
美学相关的词汇: aesthetics.fandom.com/wiki/List_o…
DALL-E 2 的 Prompt 技巧资料: docs.google.com/document/d/…
DiscoDiffusion Prompt 技巧资料: docs.google.com/document/d/…
四、代码
import wenxin_api from wenxin_api.tasks.text_to_image import TextToImage import requests import argparse import sys import os styleDict = ["油画", "水彩", "卡通", "粉笔画", "儿童画", "蜡笔画"] class MV: def __init__(self): pass def getImageDict(self, text): input_dict = { "text": text, "style": self.style, } return TextToImage.create(**input_dict) def readAndSave(self, imgDict, text=None, ind=0): for index, url in enumerate(imgDict['imgUrls']): r = requests.get(url) imgName = "" if text is None: imgName = imgName + url.split('/')[-1] + '.png' else: imgName = imgName + str(ind) + "_" + text + "_" + str(index) + '.png' out_ii = os.path.join(self.songName, imgName) with open(out_ii, 'wb') as f: f.write(r.content) f.close() def make(self, lrc=None, songName=None, style=0, startindex=0): if style < 6 and style >= 0: self.style = styleDict[style] else: try: sys.exit(0) except: print("Wrong Style") self.lrcs = [] if os.path.exists(lrc): with open(lrc, 'r', encoding='UTF-8') as fp: lines = fp.readlines() for line in lines: self.lrcs.append(line) else: self.lrcs.append(lrc) print(self.lrcs) if songName is not None: self.songName = songName else: if os.path.exists(lrc): self.songName = os.path.basename(lrc).split(".")[0] else: self.songName = lrc os.makedirs(self.songName, exist_ok=True) for index, txt in enumerate(self.lrcs): print(index, txt) if index >= startindex: textlist = txt.split("@:") if len(textlist) > 1 and textlist[-1] is not '': txt = textlist[-1] txt = txt.replace("\n", "") txt = txt + "中国风,像素艺术" print("real text:", txt) idict = self.getImageDict(txt) self.readAndSave(idict, text=txt, ind=index) wenxin_api.ak = "xxxxxxxx" wenxin_api.sk = "xxxxxxxxx" mv = MV() def main(args): mv.make(args.lrc, args.songName, args.style, args.startindex) if __name__ == '__main__': parser = argparse.ArgumentParser() parser.add_argument('--lrc', type=str, required=True) parser.add_argument('--songName', type=str, required=False) parser.add_argument('--style', type=int, default=0, required=False) parser.add_argument('--startindex', type=int, default=0, required=False) args = parser.parse_args() main(args)