🚀 BeautifulPrompt-v2
我們開源了一個自動Prompt生成模型,只需輸入極其簡單的Prompt,就能得到經語言模型優化的結果,助力更輕鬆地生成高顏值圖像。相比v1版本,該模型在複雜場景下表現更優,還新增了生成權重(可配合sd - webui使用)的能力。
🚀 快速開始
本項目是一個自動Prompt生成模型,您可以通過輸入簡單的Prompt,利用語言模型優化得到更適合生成高顏值圖像的Prompt。
✨ 主要特性
- 輸入簡單:可直接輸入極其簡單的Prompt。
- 效果提升:相比[v1](https://huggingface.co/alibaba - pai/pai - bloom - 1b1 - text2prompt - sd),在複雜場景下表現更佳。
- 功能擴展:增加了生成權重(配合sd - webui使用)的能力。
📦 安裝指南
使用該模型前,您需要安裝transformers
庫,可使用以下命令進行安裝:
pip install transformers
💻 使用示例
基礎用法
from transformers import AutoTokenizer, AutoModelForCausalLM
tokenizer = AutoTokenizer.from_pretrained('alibaba - pai/pai - bloom - 1b1 - text2prompt - sd - v2')
model = AutoModelForCausalLM.from_pretrained('alibaba - pai/pai - bloom - 1b1 - text2prompt - sd - v2').eval().cuda()
raw_prompt = '1 girl'
TEMPLATE_V2 = 'Converts a simple image description into a prompt. \
Prompts are formatted as multiple related tags separated by commas, plus you can use () to increase the weight, [] to decrease the weight, \
or use a number to specify the weight. You should add appropriate words to make the images described in the prompt more aesthetically pleasing, \
but make sure there is a correlation between the input and output.\n\
### Input: {raw_prompt}\n### Output:'
input = TEMPLATE_V2.format(raw_prompt=raw_prompt)
input_ids = tokenizer.encode(input, return_tensors='pt').cuda()
outputs = model.generate(
input_ids,
max_new_tokens=384,
do_sample=True,
temperature=0.9,
top_k=50,
top_p=0.95,
repetition_penalty=1.1,
num_return_sequences=5)
prompts = tokenizer.batch_decode(outputs[:, input_ids.size(1):], skip_special_tokens=True)
prompts = [p.strip() for p in prompts]
print(prompts)
📚 詳細文檔
作品展示
優化前 |
優化後 |
prompt: a beautiful girl |
prompt: (8k, RAW photo, best quality, masterpiece:1.2), (realistic, photo - realistic:1.37), octane render, ultra high res, photon mapping, radiosity, physically - based rendering, ue5, ((white dress)), ((long hair)), ((beautiful face)), ((light brown eyes)), ((smile))) extremely detailed CG unity 8k wallpaper, makeup, (glowing lips), (fantasy lining), (intricate details), light bokeh, (sharp focus) centered at the center of the face (wide angle:0.6), full body |
  |
  |
優化前 |
優化後 |
prompt: Astronaut rides horse |
prompt: (masterpiece), (best quality), astronaut on horseback, (rides horse), ( helmet ), (standing on horseback), panorama, looking ahead, detailed background, solo |
  |
  |
以上圖片由[sd - xl - 1.0](https://huggingface.co/stabilityai/stable - diffusion - xl - base - 1.0)生成
使用須知
使用上述模型需遵守[AIGC模型開源特別條款](https://terms.alicdn.com/legal - agreement/terms/common_platform_service/20230505180457947/20230505180457947.html)。
Paper Citation
如果您覺得該模型有用,請考慮引用以下論文:
@inproceedings{emnlp2023a,
author = {Tingfeng Cao and
Chengyu Wang and
Bingyan Liu and
Ziheng Wu and
Jinhui Zhu and
Jun Huang},
title = {BeautifulPrompt: Towards Automatic Prompt Engineering for Text - to - Image Synthesis},
booktitle = {Proceedings of the 2023 Conference on Empirical Methods in Natural Language Processing: Industry Track},
pages = {1--11},
year = {2023}
}
📄 許可證
本項目採用Apache - 2.0許可證。