Views
No views yet
1from transformers import AutoTokenizer, AutoModelForCausalLM
2
3tokenizer = AutoTokenizer.from_pretrained('alibaba-pai/pai-bloom-1b1-text2prompt-sd')
4model = AutoModelForCausalLM.from_pretrained('alibaba-pai/pai-bloom-1b1-text2prompt-sd').eval().cuda()
5
6raw_prompt = '1 girl'
7input = f'Instruction: Give a simple description of the image to generate a drawing prompt.\nInput: {raw_prompt}\nOutput:'
8input_ids = tokenizer.encode(input, return_tensors='pt').cuda()
9
10outputs = model.generate(
11 input_ids,
12 max_length=384,
13 do_sample=True,
14 temperature=1.0,
15 top_k=50,
16 top_p=0.95,
17 repetition_penalty=1.2,
18 num_return_sequences=5)
19
20prompts = tokenizer.batch_decode(outputs[:, input_ids.size(1):], skip_special_tokens=True)
21prompts = [p.strip() for p in prompts]
22print(prompts)| Original | BeautifulPrompt |
|---|---|
| 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 |
![]() | ![]() |
| Original | BeautifulPrompt |
|---|---|
| prompt: A majestic sailing ship | prompt: a massive sailing ship, epic, cinematic, artstation, greg rutkowski, james gurney, sparth |
![]() | ![]() |
@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}
}