Spaces:
Runtime error
Runtime error
HardWorkingStation
commited on
Commit
β’
36893e0
1
Parent(s):
ae92ccd
Initial commit
Browse files
README.md
CHANGED
@@ -1,8 +1,8 @@
|
|
1 |
---
|
2 |
title: Play With Stable Diffusion V1-4
|
3 |
emoji: π
|
4 |
-
colorFrom:
|
5 |
-
colorTo:
|
6 |
sdk: streamlit
|
7 |
sdk_version: 1.10.0
|
8 |
app_file: app.py
|
1 |
---
|
2 |
title: Play With Stable Diffusion V1-4
|
3 |
emoji: π
|
4 |
+
colorFrom: red
|
5 |
+
colorTo: greem
|
6 |
sdk: streamlit
|
7 |
sdk_version: 1.10.0
|
8 |
app_file: app.py
|
app.py
ADDED
@@ -0,0 +1,85 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import streamlit as st
|
2 |
+
|
3 |
+
import torch
|
4 |
+
from torch import autocast
|
5 |
+
from diffusers import StableDiffusionPipeline
|
6 |
+
|
7 |
+
|
8 |
+
st.set_page_config(layout="wide")
|
9 |
+
|
10 |
+
st.title('Play with Stable-Diffusion v1-4')
|
11 |
+
|
12 |
+
model_id = "CompVis/stable-diffusion-v1-4"
|
13 |
+
device = "cuda"
|
14 |
+
|
15 |
+
with st.spinner(
|
16 |
+
text='Loading...'
|
17 |
+
):
|
18 |
+
pipe = StableDiffusionPipeline.from_pretrained(
|
19 |
+
model_id,
|
20 |
+
revision="fp16",
|
21 |
+
torch_dtype=torch.float16,
|
22 |
+
use_auth_token=True
|
23 |
+
)
|
24 |
+
|
25 |
+
pipe = pipe.to(device)
|
26 |
+
|
27 |
+
|
28 |
+
def infer(prompt, samples=2, steps=30, scale=7.5, seed=25):
|
29 |
+
generator = torch.Generator(device=device).manual_seed(seed)
|
30 |
+
|
31 |
+
with autocast("cuda"):
|
32 |
+
images_list = pipe(
|
33 |
+
[prompt] * samples,
|
34 |
+
num_inference_steps=steps,
|
35 |
+
guidance_scale=scale,
|
36 |
+
generator=generator,
|
37 |
+
)
|
38 |
+
|
39 |
+
images = []
|
40 |
+
for image in images_list["sample"]:
|
41 |
+
images.append(image)
|
42 |
+
|
43 |
+
return images
|
44 |
+
|
45 |
+
|
46 |
+
with st.form(key='new'):
|
47 |
+
|
48 |
+
prompt = st.text_area(label='Enter prompt')
|
49 |
+
|
50 |
+
col1, col2, col3 = st.columns(3)
|
51 |
+
|
52 |
+
with col1:
|
53 |
+
with st.expander(label='Expand parameters'):
|
54 |
+
n_samples = st.select_slider(
|
55 |
+
label='Num images',
|
56 |
+
options=range(1, 5),
|
57 |
+
value=1
|
58 |
+
)
|
59 |
+
|
60 |
+
steps = st.select_slider(
|
61 |
+
label='Steps',
|
62 |
+
options=range(1, 61),
|
63 |
+
value=40
|
64 |
+
)
|
65 |
+
|
66 |
+
scale = st.select_slider(
|
67 |
+
label='Guidance Scale',
|
68 |
+
options=range(1, 21),
|
69 |
+
value=7
|
70 |
+
)
|
71 |
+
|
72 |
+
st.form_submit_button()
|
73 |
+
|
74 |
+
if prompt:
|
75 |
+
st.image(
|
76 |
+
infer(
|
77 |
+
prompt,
|
78 |
+
samples=n_samples,
|
79 |
+
steps=steps,
|
80 |
+
scale=scale
|
81 |
+
),
|
82 |
+
caption='result'
|
83 |
+
)
|
84 |
+
else:
|
85 |
+
st.warning('Enter prompt.')
|