Update app.py
Browse files
app.py
CHANGED
|
@@ -4,8 +4,7 @@ import time
|
|
| 4 |
import torch
|
| 5 |
from diffusers import StableDiffusionPipeline
|
| 6 |
|
| 7 |
-
|
| 8 |
-
# "CompVis/stable-diffusion-v1-4"
|
| 9 |
def create_model(loc = "stabilityai/stable-diffusion-2-1-base", mch = 'cpu'):
|
| 10 |
pipe = StableDiffusionPipeline.from_pretrained(loc)
|
| 11 |
pipe = pipe.to(mch)
|
|
@@ -19,16 +18,18 @@ Txt2Img
|
|
| 19 |
|
| 20 |
the_type = st.selectbox("Model",("stabilityai/stable-diffusion-2-1-base",
|
| 21 |
"CompVis/stable-diffusion-v1-4"))
|
|
|
|
| 22 |
create = st.button("Create The Model")
|
| 23 |
|
| 24 |
if create:
|
| 25 |
st.session_state.t2m_mod = create_model(loc=the_type)
|
| 26 |
-
|
| 27 |
|
| 28 |
prom = st.text_input("# Prompt",'')
|
| 29 |
|
| 30 |
c1,c2,c3 = st.columns([1,1,3])
|
| 31 |
c4,c5 = st.columns(2)
|
|
|
|
| 32 |
with c1:
|
| 33 |
bu_1 = st.text_input("Seed",'999')
|
| 34 |
with c2:
|
|
@@ -41,26 +42,22 @@ with c5:
|
|
| 41 |
sl_2 = st.slider("hight",128,1024,512,8)
|
| 42 |
|
| 43 |
create = st.button("Imagine")
|
|
|
|
| 44 |
if create:
|
| 45 |
-
|
| 46 |
-
|
| 47 |
-
# img = model(prom, width=int(sl_1), height=int(sl_2), num_inference_steps=int(bu_2), generator=generator).images[0]
|
| 48 |
-
# st.image(img)
|
| 49 |
|
| 50 |
if int(bu_3) == 1 :
|
| 51 |
-
generator = torch.Generator("cpu").manual_seed(int(bu_1))
|
| 52 |
-
model = st.session_state.t2m_mod
|
| 53 |
IMG = model(prom, width=int(sl_1), height=int(sl_2),
|
| 54 |
num_inference_steps=int(bu_2),
|
| 55 |
generator=generator).images[0]
|
| 56 |
st.image(IMG)
|
|
|
|
| 57 |
else :
|
| 58 |
-
generator = torch.Generator("cpu").manual_seed(int(bu_1))
|
| 59 |
PROMS = [prom]*int(bu_3)
|
| 60 |
-
|
| 61 |
IMGS = model(PROMS, width=int(sl_1), height=int(sl_2),
|
| 62 |
num_inference_steps=int(bu_2),
|
| 63 |
generator=generator).images
|
| 64 |
|
| 65 |
-
# IMGS = np.hstack(IMGS)
|
| 66 |
st.image(IMGS)
|
|
|
|
| 4 |
import torch
|
| 5 |
from diffusers import StableDiffusionPipeline
|
| 6 |
|
| 7 |
+
|
|
|
|
| 8 |
def create_model(loc = "stabilityai/stable-diffusion-2-1-base", mch = 'cpu'):
|
| 9 |
pipe = StableDiffusionPipeline.from_pretrained(loc)
|
| 10 |
pipe = pipe.to(mch)
|
|
|
|
| 18 |
|
| 19 |
the_type = st.selectbox("Model",("stabilityai/stable-diffusion-2-1-base",
|
| 20 |
"CompVis/stable-diffusion-v1-4"))
|
| 21 |
+
|
| 22 |
create = st.button("Create The Model")
|
| 23 |
|
| 24 |
if create:
|
| 25 |
st.session_state.t2m_mod = create_model(loc=the_type)
|
| 26 |
+
st.session_state.generator = torch.Generator("cpu").manual_seed(int(bu_1))
|
| 27 |
|
| 28 |
prom = st.text_input("# Prompt",'')
|
| 29 |
|
| 30 |
c1,c2,c3 = st.columns([1,1,3])
|
| 31 |
c4,c5 = st.columns(2)
|
| 32 |
+
|
| 33 |
with c1:
|
| 34 |
bu_1 = st.text_input("Seed",'999')
|
| 35 |
with c2:
|
|
|
|
| 42 |
sl_2 = st.slider("hight",128,1024,512,8)
|
| 43 |
|
| 44 |
create = st.button("Imagine")
|
| 45 |
+
|
| 46 |
if create:
|
| 47 |
+
model = st.session_state.t2m_mod
|
| 48 |
+
generator = st.session_state.generator
|
|
|
|
|
|
|
| 49 |
|
| 50 |
if int(bu_3) == 1 :
|
|
|
|
|
|
|
| 51 |
IMG = model(prom, width=int(sl_1), height=int(sl_2),
|
| 52 |
num_inference_steps=int(bu_2),
|
| 53 |
generator=generator).images[0]
|
| 54 |
st.image(IMG)
|
| 55 |
+
|
| 56 |
else :
|
|
|
|
| 57 |
PROMS = [prom]*int(bu_3)
|
| 58 |
+
|
| 59 |
IMGS = model(PROMS, width=int(sl_1), height=int(sl_2),
|
| 60 |
num_inference_steps=int(bu_2),
|
| 61 |
generator=generator).images
|
| 62 |
|
|
|
|
| 63 |
st.image(IMGS)
|