Skip to content

Commit

Permalink
update ernie_vilg (PaddlePaddle#2098)
Browse files Browse the repository at this point in the history
* remove resolution parameter

* update README
  • Loading branch information
jm12138 committed Nov 4, 2022
1 parent fbd18e9 commit 755425c
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 22 deletions.
9 changes: 6 additions & 3 deletions modules/image/text_to_image/ernie_vilg/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,6 @@
def generate_image(
text_prompts:str,
style: Optional[str] = "探索无限",
resolution: Optional[str] = "1024*1024",
topk: Optional[int] = 6,
output_dir: Optional[str] = 'ernievilg_output')
```
Expand All @@ -91,7 +90,6 @@
- text_prompts(str): 输入的语句,描述想要生成的图像的内容。
- style(Optional[str]): 生成图像的风格,当前支持 古风、油画、水彩、卡通、二次元、浮世绘、蒸汽波艺术、
low poly、像素风格、概念艺术、未来主义、赛博朋克、写实风格、洛丽塔风格、巴洛克风格、超现实主义、探索无限。
- resolution(Optional[str]): 生成图像的分辨率,当前支持 '1024\*1024', '1024\*1536', '1536\*1024',默认为'1024\*1024'
- topk(Optional[int]): 保存前多少张图,最多保存6张。
- output_dir(Optional[str]): 保存输出图像的目录,默认为"ernievilg_output"

Expand Down Expand Up @@ -389,6 +387,11 @@ DiscoDiffusion Prompt 技巧资料:https://docs.google.com/document/d/1l8s7uS2
* 1.1.0
增加分辨率参数以及所支持的风格
* 1.2.0
移除分辨率参数
```shell
$ hub install ernie_vilg == 1.1.0
$ hub install ernie_vilg == 1.2.0
```
22 changes: 3 additions & 19 deletions modules/image/text_to_image/ernie_vilg/module.py
Original file line number Diff line number Diff line change
@@ -1,27 +1,21 @@
import argparse
import ast
import base64
import os
import re
import sys
import time
from functools import partial
from io import BytesIO
from typing import List
from typing import Optional

import requests
from PIL import Image
from tqdm.auto import tqdm

import paddlehub as hub
from paddlehub.module.module import moduleinfo
from paddlehub.module.module import runnable
from paddlehub.module.module import serving


@moduleinfo(name="ernie_vilg",
version="1.1.0",
version="1.2.0",
type="image/text_to_image",
summary="",
author="baidu-nlp",
Expand Down Expand Up @@ -65,7 +59,6 @@ def _apply_token(self, ak, sk):
def generate_image(self,
text_prompts,
style: Optional[str] = "探索无限",
resolution: Optional[str] = "1024*1024",
topk: Optional[int] = 6,
visualization: Optional[bool] = True,
output_dir: Optional[str] = 'ernievilg_output'):
Expand All @@ -75,7 +68,6 @@ def generate_image(self,
:param text_prompts: Phrase, sentence, or string of words and phrases describing what the image should look like.
:param style: Image stype, currently supported 古风、油画、水彩、卡通、二次元、浮世绘、蒸汽波艺术、
low poly、像素风格、概念艺术、未来主义、赛博朋克、写实风格、洛丽塔风格、巴洛克风格、超现实主义、探索无限。
:param resolution: Resolution of images, currently supported "1024*1024", "1024*1536", "1536*1024".
:param topk: Top k images to save.
:param visualization: Whether to save images or not.
:output_dir: Output directory
Expand All @@ -94,8 +86,7 @@ def generate_image(self,
data={
'access_token': token,
"text": text_prompt,
"style": style,
"resolution": resolution
"style": style
})
res = res.json()
if res['code'] == 4001:
Expand All @@ -117,8 +108,7 @@ def generate_image(self,
data={
'access_token': token,
"text": text_prompt,
"style": style,
"resolution": resolution
"style": style
})
res = res.json()
if res['code'] != 0:
Expand Down Expand Up @@ -242,7 +232,6 @@ def run_cmd(self, argvs):
self.token = self._apply_token(self.ak, self.sk)
results = self.generate_image(text_prompts=args.text_prompts,
style=args.style,
resolution=args.resolution,
topk=args.topk,
visualization=args.visualization,
output_dir=args.output_dir)
Expand Down Expand Up @@ -275,11 +264,6 @@ def add_module_input_arg(self):
'未来主义', '赛博朋克', '写实风格', '洛丽塔风格', '巴洛克风格', '超现实主义', '探索无限'
],
help="绘画风格")
self.arg_input_group.add_argument('--resolution',
type=str,
default='1024*1024',
choices=['1024*1024', '1024*1536', '1536*1024'],
help="图像分辨率")
self.arg_input_group.add_argument('--topk', type=int, default=6, help="选取保存前多少张图,最多10张")
self.arg_input_group.add_argument('--ak', type=str, default=None, help="申请文心api使用token的ak")
self.arg_input_group.add_argument('--sk', type=str, default=None, help="申请文心api使用token的sk")
Expand Down
26 changes: 26 additions & 0 deletions modules/image/text_to_image/ernie_vilg/test.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import shutil
import unittest

import paddlehub as hub


class TestHubModule(unittest.TestCase):

@classmethod
def setUpClass(cls) -> None:
cls.module = hub.Module(name="ernie_vilg")

@classmethod
def tearDownClass(cls) -> None:
shutil.rmtree('ernievilg_output')

def test_generate_image(self):
self.module.generate_image(text_prompts=['戴眼镜的猫'],
style="探索无限",
topk=6,
visualization=True,
output_dir='ernievilg_output')


if __name__ == "__main__":
unittest.main()

0 comments on commit 755425c

Please sign in to comment.