Spaces:
Sleeping
Sleeping
Commit
·
e6b153f
1
Parent(s):
898f328
retooled to use old hugginface pipline instead
Browse files- app.py +44 -30
- requirements.txt +3 -1
app.py
CHANGED
@@ -1,35 +1,49 @@
|
|
1 |
# Python
|
2 |
import streamlit as st
|
3 |
-
|
4 |
-
from
|
5 |
-
|
6 |
-
|
7 |
-
|
8 |
-
|
9 |
-
|
10 |
-
|
11 |
-
|
12 |
-
|
13 |
-
|
14 |
-
|
15 |
-
|
16 |
-
|
17 |
-
|
18 |
-
|
19 |
-
|
20 |
-
prompt=prompt,
|
21 |
-
size="1024x1024",
|
22 |
-
quality="standard",
|
23 |
-
n=1,
|
24 |
)
|
25 |
-
|
26 |
-
|
27 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
28 |
|
29 |
-
# if images: #display images
|
30 |
-
|
31 |
-
# image_path1 = 'path_to_image1_based_on_prompt' # Replace with actual logic
|
32 |
-
# image_path2 = 'path_to_image2_based_on_prompt' # Replace with actual logic
|
33 |
|
34 |
-
|
35 |
-
|
|
|
|
|
|
1 |
# Python
|
2 |
import streamlit as st
|
3 |
+
import torch
|
4 |
+
from diffusers import StableCascadeDecoderPipeline, StableCascadePriorPipeline
|
5 |
+
|
6 |
+
def load_pipelines(device, dtype):
|
7 |
+
prior = StableCascadePriorPipeline.from_pretrained("stabilityai/stable-cascade-prior", torch_dtype=dtype).to(device)
|
8 |
+
decoder = StableCascadeDecoderPipeline.from_pretrained("stabilityai/stable-cascade", torch_dtype=dtype).to(device)
|
9 |
+
return prior, decoder
|
10 |
+
|
11 |
+
def generate_images(prompt, negative_prompt, num_images_per_prompt, device, dtype):
|
12 |
+
with torch.cuda.amp.autocast(dtype=dtype):
|
13 |
+
prior_output = prior(
|
14 |
+
prompt=prompt,
|
15 |
+
height=1024,
|
16 |
+
width=1024,
|
17 |
+
negative_prompt=negative_prompt,
|
18 |
+
guidance_scale=4.0,
|
19 |
+
num_images_per_prompt=num_images_per_prompt,
|
|
|
|
|
|
|
|
|
20 |
)
|
21 |
+
decoder_output = decoder(
|
22 |
+
image_embeddings=prior_output.image_embeddings,
|
23 |
+
prompt=prompt,
|
24 |
+
negative_prompt=negative_prompt,
|
25 |
+
guidance_scale=0.0,
|
26 |
+
output_type="pil",
|
27 |
+
)
|
28 |
+
return decoder_output.images
|
29 |
+
|
30 |
+
|
31 |
+
st.title("Image Generator with Diffusers")
|
32 |
+
|
33 |
+
@st.cache(allow_output_mutation=True)
|
34 |
+
def init_model():
|
35 |
+
device = "cuda" if torch.cuda.is_available() else "cpu"
|
36 |
+
dtype = torch.bfloat16
|
37 |
+
return load_pipelines(device, dtype), device, dtype
|
38 |
+
|
39 |
+
(prior, decoder), device, dtype = init_model()
|
40 |
+
|
41 |
+
prompt = st.text_input("Enter a prompt:", "Anthropomorphic cat dressed as a pilot")
|
42 |
+
negative_prompt = st.text_input("Enter a negative prompt:", "")
|
43 |
+
num_images_per_prompt = st.slider("Number of images per prompt:", 1, 5, 2)
|
44 |
|
|
|
|
|
|
|
|
|
45 |
|
46 |
+
if st.button("Generate"):
|
47 |
+
images = generate_images(prompt, negative_prompt, num_images_per_prompt, device, dtype)
|
48 |
+
for img in images:
|
49 |
+
st.image(img, use_column_width=True)
|
requirements.txt
CHANGED
@@ -1 +1,3 @@
|
|
1 |
-
|
|
|
|
|
|
1 |
+
streamlit
|
2 |
+
torch
|
3 |
+
git+https://github.com/kashif/diffusers.git@wuerstchen-v3
|