GIGAZINEの記事通りにやったもののエラーで動かなかった人向けでもある。
一番簡単な方法
1.からあげ氏のGithubのノートブックを開く
2.Open in Colabを押す
3.ランタイムのタイプをGPUに変更する
4.上から順番に再生ボタンを押して実行する
一つ目の再生ボタンの左に緑のチェックマークが付いたら成功。
次に二つ目の再生ボタンを押す。
画像のURLをクリックすると、UIを別画面で開くことができる。
「RUN」の左のテキストボックスにパラメータを入力する。
下のゲージは出力する絵のスタイルで、それぞれ「0: 油絵 1: 水彩 2: チョークで描く 3: 漫画 4: クレヨンで描く 5: 子供の絵を描く 6: 無限を探求する」となっている。
GIGAZINEの手法(修正版)
GIGAZINEの手法はなぜエラーが出るのか?
2つ目のコードで
import gradio as gr
というgrの定義が漏れている。
よって、GIGAZINEの手法は以下の通りとなる。
1.GoogleColabを開く
2.からあげ氏のノートブックの1ブロック目をコピペし実行する。
#@title **Download model** #@markdown Run !pip install -qq paddlepaddle-gpu -U !pip install -qq paddlehub==2.1.0 !pip install -qq gradio import os import datetime import paddlehub as hub module = hub.Module(name="ernie_vilg")
3.からあげ氏のノートブックの2ブロック目をコピペし実行する。
インデント(各行の先頭の空白の数)が崩れないように注意。
コピペでずれた場合は、元の記述を参考に「Tabキー」で修正すると良い。
#@title **Launch App**
#@markdown Execute and click URL ex: `Running on public URL: https://xxxx.gradio.app`
import gradio as grstyle_list = ['\u6CB9\u753B', '\u6C34\u5F69', '\u7C89\u7B14\u753B', '\u5361\u901A', '\u513F\u7AE5\u753B', '\u8721\u7B14\u753B', '\u63A2\u7D22\u65E0\u9650']
def infer(prompt, num_images, style_numb):
num_images = int(num_images)
style_numb = int(style_numb)image_list = []
for num in range(num_images):
images = module.generate_image(text_prompts=[prompt], style=style_list[style_numb], visualization=False)
image_list.append(images[0])return image_list
from IPython.display import clear_outputblock = gr.Blocks(css=".container { max-width: 800px; margin: auto; }")
with block as demo:
gr.Markdown("<h1><center>Stable Diffusion Tool ERNIE-ViLG</center></h1>")
gr.Markdown(
'Stable Diffusion useful web tool ERNIE-ViLG version'
)
with gr.Group():
with gr.Box():
gr.Markdown(
'Enter prompt and Run!!'
)
with gr.Row().style(mobile_collapse=False, equal_height=True):text = gr.Textbox(
label='Enter prompt', show_label=False, max_lines=1
).style(
border=(True, False, True, True),
rounded=(True, False, False, True),
container=False,
)
btn = gr.Button("Run").style(
margin=False,
rounded=(False, True, True, False),
)num_images = gr.Number(
label='Number of images', value=3
)
style_numb = gr.Slider(
label='Style 0:油画 1:水彩 2:粉笔画(Chalk drawing) 3:卡通(Cartoon) 4:蜡笔画(Crayon drawing) 5:儿童画(Children drawing) 6:探索无限(Explore infinity)', minimum=0, maximum=6, value=0, step=1
)
gallery = gr.Gallery(label="Generated images", show_label=False).style(
grid=[2], height="auto"
)btn.click(infer,
inputs=[text, num_images, style_numb], outputs=gallery)gr.Markdown(
"""___
<p style='text-align: center'>
Created by CompVis and Stability AI
<br/>
</p>"""
)clear_output()
demo.launch(debug=True)
おまけ:生成データ
1.GIGAZINEと同じパラメーターで、styleを0にしたもの
「猿の惑星2022」かよ
2.GIGAZINEと同じパラメーター(成功作)
昔の大判コミックって大体こんな絵柄だったよね
3.GIGAZINEと同じパラメーター(失敗作)
FXで全財産とかした後に食うハンバーガーはうまいか?