How to install and run 'GUI Tool ERNIE-ViLG version' on Google Colab that makes it easy to create illustrations from a browser with Chinese image generation AI 'ERNIE-ViLG' Summary



The image generation AI developed by Baidu in China is '

ERNIE-ViLG '. ERNIE-ViLG has more than 10 billion parameter scales and has been trained on a large dataset consisting of more than 145 million types of images and texts. It is said. Mr. Karaage, an engineer, has published a notebook for running ERNIE- ViLG on Google Colaboratory (Google Colab) , a service that allows you to write and execute Python on a browser and access Google's GPU for free. So I actually tried using it.

stable-diffusion-colab-tools/003_stable_diffusion_gui_ERNIE_ViLG.ipynb at main karaage0703/stable-diffusion-colab-tools GitHub
https://github.com/karaage0703/stable-diffusion-colab-tools/blob/main/003_stable_diffusion_gui_ERNIE_ViLG.ipynb

First, copy the following code from the notebook published by Mr. Karaage .
[code]!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')[/code]

Next, log in to Google Colab, create a new notebook, and click '+ Code' in the upper left.



After pasting and entering the code you copied earlier, click the play icon to execute.



A green check icon will appear to the left of the play icon when complete. Next, click '+ Code'.



And copy the code below from the published notebook.
[code]#@title **Launch App**
#@markdown Execute and click URL ex: `Running on public URL: https://xxxx.gradio.app` import gradio as gr

style_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_output

block = gr.Blocks(css='.container { max-width: 800px; margin: auto; }')

with block as demo:
gr. Markdown('

Stable Diffusion Tool ERNIE-ViLG

')
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: Oil painting 1: Watercolor 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(
'''___


Created by CompVis and Stability AI


'''
)

clear_output()
demo.launch(debug=True)[/code]

After pasting the copied code and entering it, click the play icon to run it.



When executed, a UI for giving instructions to ERNIE-ViLG will appear below the code input field. This UI can be operated on Google Colab as it is, but by clicking the URL above the input field, you can directly access the UI from a normal browser. The valid time of the generated URL is 72 hours.



When you click the URL, it looks like this. ERNIE-ViLG is an image generation AI made in China, so prompts are available not only in English but also in Chinese. The number below the input field of the prompt determines the number of images to be generated, and the slide bar below it determines the style of the image to be generated.



This time, I dared to enter the prompt in Chinese using the translation software

DeePL . The content is ``Cute black hair girl, schoolgirl, 吃汉堡包, Japanese cartoon style (cute black hair girl, high school girl, eating a hamburger, Japanese anime style)'', the number of generated is 3, and the style is `` Set it to 卡通 (Cartoon, cartoon)' and click 'Run'.



A loading icon is displayed below the input field.



Looking at the Google Colab screen, you can see a progress bar for image generation. The generation time per sheet was about 40 seconds to 1 minute.



After confirming that the three images have been generated and returning to the UI site again, the three images generated under the input field were displayed. The generated images had a resolution of 1024 × 1024 pixels.

in Review,   Software,   Web Service,   Manga,   Art, Posted by log1i_yk