Spaces:
Runtime error
Runtime error
more knobs
Browse files
app.py
CHANGED
@@ -3,29 +3,39 @@ from PIL import Image
|
|
3 |
from transformers import pipeline as transformer
|
4 |
from diffusers import StableDiffusionPipeline
|
5 |
|
6 |
-
pipe = StableDiffusionPipeline.from_pretrained("CompVis/stable-diffusion-v1-4")
|
7 |
-
|
8 |
captions = []
|
9 |
|
10 |
with st.sidebar:
|
11 |
files = st.file_uploader("Upload images to blend", accept_multiple_files=True)
|
12 |
st.divider()
|
13 |
caption_model = st.selectbox("Caption Model", [
|
14 |
-
"ydshieh/vit-gpt2-coco-en",
|
15 |
"Salesforce/blip-image-captioning-large",
|
16 |
"nlpconnect/vit-gpt2-image-captioning",
|
17 |
-
"microsoft/git-base"
|
|
|
18 |
])
|
|
|
|
|
|
|
19 |
st.divider()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
20 |
image_gen_guidance = st.slider("Stable Diffusion: Guidance Scale", value=7.5)
|
21 |
-
|
22 |
|
23 |
for file_name in files:
|
24 |
image = Image.open(file_name)
|
25 |
|
26 |
with st.spinner('Captioning Provided Image'):
|
27 |
captioner = transformer(model=caption_model)
|
28 |
-
caption = captioner(image)[0]['generated_text']
|
29 |
|
30 |
captions.append(caption)
|
31 |
st.image(image, caption=caption)
|
@@ -33,10 +43,12 @@ for file_name in files:
|
|
33 |
if len(captions) > 0:
|
34 |
st.divider()
|
35 |
|
36 |
-
description =
|
|
|
|
|
37 |
|
38 |
with st.spinner(f'Generating Photo for "{description}"'):
|
39 |
-
images = pipe(description, guidance_scale=image_gen_guidance,
|
40 |
|
41 |
for image in images:
|
42 |
st.image(image, caption=description)
|
|
|
3 |
from transformers import pipeline as transformer
|
4 |
from diffusers import StableDiffusionPipeline
|
5 |
|
|
|
|
|
6 |
captions = []
|
7 |
|
8 |
with st.sidebar:
|
9 |
files = st.file_uploader("Upload images to blend", accept_multiple_files=True)
|
10 |
st.divider()
|
11 |
caption_model = st.selectbox("Caption Model", [
|
|
|
12 |
"Salesforce/blip-image-captioning-large",
|
13 |
"nlpconnect/vit-gpt2-image-captioning",
|
14 |
+
"microsoft/git-base",
|
15 |
+
"ydshieh/vit-gpt2-coco-en"
|
16 |
])
|
17 |
+
caption_max_tokens = st.number_input("Image Caption: Max Tokens")
|
18 |
+
st.divider()
|
19 |
+
caption_concat_joiner = st.text_input("Caption Concatenation Joiner", value=" ")
|
20 |
st.divider()
|
21 |
+
diffusion_model = st.selectbox("Diffusion Model", [
|
22 |
+
"stabilityai/stable-diffusion-xl-base-1.0",
|
23 |
+
"runwayml/stable-diffusion-v1-5",
|
24 |
+
"stabilityai/stable-diffusion-2-1",
|
25 |
+
"CompVis/stable-diffusion-v1-4"
|
26 |
+
])
|
27 |
+
image_gen_height = st.number_input("Stable Diffusion: Height", value=512)
|
28 |
+
image_gen_width = st.number_input("Stable Diffusion: Width", value=512)
|
29 |
+
image_gen_steps = st.slider("Stable Diffusion: Inference Steps", value=50)
|
30 |
image_gen_guidance = st.slider("Stable Diffusion: Guidance Scale", value=7.5)
|
31 |
+
image_gen_number = st.number_input("Stable Diffusion: Images Generates", value=1)
|
32 |
|
33 |
for file_name in files:
|
34 |
image = Image.open(file_name)
|
35 |
|
36 |
with st.spinner('Captioning Provided Image'):
|
37 |
captioner = transformer(model=caption_model)
|
38 |
+
caption = captioner(image, max_new_tokens=caption_max_tokens)[0]['generated_text']
|
39 |
|
40 |
captions.append(caption)
|
41 |
st.image(image, caption=caption)
|
|
|
43 |
if len(captions) > 0:
|
44 |
st.divider()
|
45 |
|
46 |
+
description = caption_concat_joiner.join(captions)
|
47 |
+
|
48 |
+
pipe = StableDiffusionPipeline.from_pretrained(diffusion_model)
|
49 |
|
50 |
with st.spinner(f'Generating Photo for "{description}"'):
|
51 |
+
images = pipe(description, height=image_gen_height, width=image_gen_width, num_inference_steps=image_gen_steps, guidance_scale=image_gen_guidance, num_images_per_prompt=image_gen_number).images
|
52 |
|
53 |
for image in images:
|
54 |
st.image(image, caption=description)
|