🚀 BeautifulPrompt
我們開源了一個自動Prompt生成模型,用戶只需輸入極其簡單的Prompt,就能得到經語言模型優化的Prompt,從而更輕鬆地生成高顏值圖像。
🚀 快速開始
代碼示例
from transformers import AutoTokenizer, AutoModelForCausalLM
tokenizer = AutoTokenizer.from_pretrained('alibaba-pai/pai-bloom-1b1-text2prompt-sd')
model = AutoModelForCausalLM.from_pretrained('alibaba-pai/pai-bloom-1b1-text2prompt-sd').eval().cuda()
raw_prompt = '1 girl'
input = f'Instruction: Give a simple description of the image to generate a drawing prompt.\nInput: {raw_prompt}\nOutput:'
input_ids = tokenizer.encode(input, return_tensors='pt').cuda()
outputs = model.generate(
input_ids,
max_length=384,
do_sample=True,
temperature=1.0,
top_k=50,
top_p=0.95,
repetition_penalty=1.2,
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。
- 優化輸出:得到經過語言模型優化過的Prompt,有助於生成更美觀的圖像。
💻 使用示例
基礎用法
from transformers import AutoTokenizer, AutoModelForCausalLM
tokenizer = AutoTokenizer.from_pretrained('alibaba-pai/pai-bloom-1b1-text2prompt-sd')
model = AutoModelForCausalLM.from_pretrained('alibaba-pai/pai-bloom-1b1-text2prompt-sd').eval().cuda()
raw_prompt = '1 girl'
input = f'Instruction: Give a simple description of the image to generate a drawing prompt.\nInput: {raw_prompt}\nOutput:'
input_ids = tokenizer.encode(input, return_tensors='pt').cuda()
outputs = model.generate(
input_ids,
max_length=384,
do_sample=True,
temperature=1.0,
top_k=50,
top_p=0.95,
repetition_penalty=1.2,
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 |
BeautifulPrompt優化後的Prompt |
prompt: taylor swift, country, golden, fearless,wavehair |
prompt: portrait of taylor swift as a beautiful woman, long hair, country, golden ratio, intricate, symmetrical, cinematic lighting, highly detailed, digital painting, artstation, concept art, smooth, sharp focus, illustration |
 |
 |
prompt: A majestic sailing ship |
prompt: a massive sailing ship, epic, cinematic, artstation, greg rutkowski, james gurney, sparth |
 |
 |
使用須知
⚠️ 重要提示
使用上述模型需遵守AIGC模型開源特別條款。
論文引用
如果您覺得該模型有用,請考慮引用以下論文:
@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許可證。