Views
No views yet
1from transformers import AutoTokenizer, AutoModelForCausalLM
2tokenizer = AutoTokenizer.from_pretrained('alibaba-pai/pai-bloom-1b1-text2prompt-sd-v2')
3model = AutoModelForCausalLM.from_pretrained('alibaba-pai/pai-bloom-1b1-text2prompt-sd-v2').eval().cuda()
4raw_prompt = '1 girl'
5
6TEMPLATE_V2 = 'Converts a simple image description into a prompt. \
7Prompts are formatted as multiple related tags separated by commas, plus you can use () to increase the weight, [] to decrease the weight, \
8or use a number to specify the weight. You should add appropriate words to make the images described in the prompt more aesthetically pleasing, \
9but make sure there is a correlation between the input and output.\n\
10### Input: {raw_prompt}\n### Output:'
11
12input = TEMPLATE_V2.format(raw_prompt=raw_prompt)
13input_ids = tokenizer.encode(input, return_tensors='pt').cuda()
14outputs = model.generate(
15 input_ids,
16 max_new_tokens=384,
17 do_sample=True,
18 temperature=0.9,
19 top_k=50,
20 top_p=0.95,
21 repetition_penalty=1.1,
22 num_return_sequences=5)
23
24prompts = tokenizer.batch_decode(outputs[:, input_ids.size(1):], skip_special_tokens=True)
25prompts = [p.strip() for p in prompts]
26print(prompts)| Before | After |
|---|---|
| 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 |
![]() ![]() | ![]() ![]() |
| Before | After |
|---|---|
| prompt: Astronaut rides horse | prompt: (masterpiece), (best quality), astronaut on horseback, (rides horse), ( helmet ), (standing on horseback), panorama, looking ahead, detailed background, solo |
![]() ![]() | ![]() ![]() |
generated by sd-xl-1.0
@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}
}