Spaces:
Runtime error
Runtime error
Commit
•
6e5e1d5
0
Parent(s):
SD3.5 Large Public Release
Browse filesCo-authored-by: multimodalart <multimodalart@users.noreply.huggingface.co>
- .gitattributes +35 -0
- README.md +14 -0
- app.py +151 -0
- requirements.txt +6 -0
.gitattributes
ADDED
@@ -0,0 +1,35 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
*.7z filter=lfs diff=lfs merge=lfs -text
|
2 |
+
*.arrow filter=lfs diff=lfs merge=lfs -text
|
3 |
+
*.bin filter=lfs diff=lfs merge=lfs -text
|
4 |
+
*.bz2 filter=lfs diff=lfs merge=lfs -text
|
5 |
+
*.ckpt filter=lfs diff=lfs merge=lfs -text
|
6 |
+
*.ftz filter=lfs diff=lfs merge=lfs -text
|
7 |
+
*.gz filter=lfs diff=lfs merge=lfs -text
|
8 |
+
*.h5 filter=lfs diff=lfs merge=lfs -text
|
9 |
+
*.joblib filter=lfs diff=lfs merge=lfs -text
|
10 |
+
*.lfs.* filter=lfs diff=lfs merge=lfs -text
|
11 |
+
*.mlmodel filter=lfs diff=lfs merge=lfs -text
|
12 |
+
*.model filter=lfs diff=lfs merge=lfs -text
|
13 |
+
*.msgpack filter=lfs diff=lfs merge=lfs -text
|
14 |
+
*.npy filter=lfs diff=lfs merge=lfs -text
|
15 |
+
*.npz filter=lfs diff=lfs merge=lfs -text
|
16 |
+
*.onnx filter=lfs diff=lfs merge=lfs -text
|
17 |
+
*.ot filter=lfs diff=lfs merge=lfs -text
|
18 |
+
*.parquet filter=lfs diff=lfs merge=lfs -text
|
19 |
+
*.pb filter=lfs diff=lfs merge=lfs -text
|
20 |
+
*.pickle filter=lfs diff=lfs merge=lfs -text
|
21 |
+
*.pkl filter=lfs diff=lfs merge=lfs -text
|
22 |
+
*.pt filter=lfs diff=lfs merge=lfs -text
|
23 |
+
*.pth filter=lfs diff=lfs merge=lfs -text
|
24 |
+
*.rar filter=lfs diff=lfs merge=lfs -text
|
25 |
+
*.safetensors filter=lfs diff=lfs merge=lfs -text
|
26 |
+
saved_model/**/* filter=lfs diff=lfs merge=lfs -text
|
27 |
+
*.tar.* filter=lfs diff=lfs merge=lfs -text
|
28 |
+
*.tar filter=lfs diff=lfs merge=lfs -text
|
29 |
+
*.tflite filter=lfs diff=lfs merge=lfs -text
|
30 |
+
*.tgz filter=lfs diff=lfs merge=lfs -text
|
31 |
+
*.wasm filter=lfs diff=lfs merge=lfs -text
|
32 |
+
*.xz filter=lfs diff=lfs merge=lfs -text
|
33 |
+
*.zip filter=lfs diff=lfs merge=lfs -text
|
34 |
+
*.zst filter=lfs diff=lfs merge=lfs -text
|
35 |
+
*tfevents* filter=lfs diff=lfs merge=lfs -text
|
README.md
ADDED
@@ -0,0 +1,14 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
---
|
2 |
+
title: Stable Diffusion 3.5 Large
|
3 |
+
emoji: 🏃
|
4 |
+
colorFrom: purple
|
5 |
+
colorTo: blue
|
6 |
+
sdk: gradio
|
7 |
+
sdk_version: 5.3.0
|
8 |
+
app_file: app.py
|
9 |
+
pinned: true
|
10 |
+
license: other
|
11 |
+
short_description: Generate images with SD3.5
|
12 |
+
---
|
13 |
+
|
14 |
+
Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
|
app.py
ADDED
@@ -0,0 +1,151 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import gradio as gr
|
2 |
+
import numpy as np
|
3 |
+
import random
|
4 |
+
|
5 |
+
import spaces
|
6 |
+
from diffusers import DiffusionPipeline
|
7 |
+
import torch
|
8 |
+
|
9 |
+
device = "cuda" if torch.cuda.is_available() else "cpu"
|
10 |
+
model_repo_id = "stabilityai/stable-diffusion-3.5-large"
|
11 |
+
|
12 |
+
if torch.cuda.is_available():
|
13 |
+
torch_dtype = torch.bfloat16
|
14 |
+
else:
|
15 |
+
torch_dtype = torch.float32
|
16 |
+
|
17 |
+
pipe = DiffusionPipeline.from_pretrained(model_repo_id, torch_dtype=torch_dtype)
|
18 |
+
pipe = pipe.to(device)
|
19 |
+
|
20 |
+
MAX_SEED = np.iinfo(np.int32).max
|
21 |
+
MAX_IMAGE_SIZE = 1024
|
22 |
+
|
23 |
+
@spaces.GPU(duration=65)
|
24 |
+
def infer(
|
25 |
+
prompt,
|
26 |
+
negative_prompt="",
|
27 |
+
seed=42,
|
28 |
+
randomize_seed=False,
|
29 |
+
width=1024,
|
30 |
+
height=1024,
|
31 |
+
guidance_scale=4.5,
|
32 |
+
num_inference_steps=40,
|
33 |
+
progress=gr.Progress(track_tqdm=True),
|
34 |
+
):
|
35 |
+
if randomize_seed:
|
36 |
+
seed = random.randint(0, MAX_SEED)
|
37 |
+
|
38 |
+
generator = torch.Generator().manual_seed(seed)
|
39 |
+
|
40 |
+
image = pipe(
|
41 |
+
prompt=prompt,
|
42 |
+
negative_prompt=negative_prompt,
|
43 |
+
guidance_scale=guidance_scale,
|
44 |
+
num_inference_steps=num_inference_steps,
|
45 |
+
width=width,
|
46 |
+
height=height,
|
47 |
+
generator=generator,
|
48 |
+
).images[0]
|
49 |
+
|
50 |
+
return image, seed
|
51 |
+
|
52 |
+
|
53 |
+
examples = [
|
54 |
+
"A capybara wearing a suit holding a sign that reads Hello World",
|
55 |
+
]
|
56 |
+
|
57 |
+
css = """
|
58 |
+
#col-container {
|
59 |
+
margin: 0 auto;
|
60 |
+
max-width: 640px;
|
61 |
+
}
|
62 |
+
"""
|
63 |
+
|
64 |
+
with gr.Blocks(css=css) as demo:
|
65 |
+
with gr.Column(elem_id="col-container"):
|
66 |
+
gr.Markdown(" # [Stable Diffusion 3.5 Large (8B)](https://huggingface.co/stabilityai/stable-diffusion-3.5-large)")
|
67 |
+
gr.Markdown("[Learn more](https://stability.ai/news/introducing-stable-diffusion-3-5) about the Stable Diffusion 3.5 series. Try on [Stability AI API](https://platform.stability.ai/docs/api-reference#tag/Generate/paths/~1v2beta~1stable-image~1generate~1sd3/post), or [download model](https://huggingface.co/stabilityai/stable-diffusion-3.5-large) to run locally with ComfyUI or diffusers.")
|
68 |
+
with gr.Row():
|
69 |
+
prompt = gr.Text(
|
70 |
+
label="Prompt",
|
71 |
+
show_label=False,
|
72 |
+
max_lines=1,
|
73 |
+
placeholder="Enter your prompt",
|
74 |
+
container=False,
|
75 |
+
)
|
76 |
+
|
77 |
+
run_button = gr.Button("Run", scale=0, variant="primary")
|
78 |
+
|
79 |
+
result = gr.Image(label="Result", show_label=False)
|
80 |
+
|
81 |
+
with gr.Accordion("Advanced Settings", open=False):
|
82 |
+
negative_prompt = gr.Text(
|
83 |
+
label="Negative prompt",
|
84 |
+
max_lines=1,
|
85 |
+
placeholder="Enter a negative prompt",
|
86 |
+
visible=False,
|
87 |
+
)
|
88 |
+
|
89 |
+
seed = gr.Slider(
|
90 |
+
label="Seed",
|
91 |
+
minimum=0,
|
92 |
+
maximum=MAX_SEED,
|
93 |
+
step=1,
|
94 |
+
value=0,
|
95 |
+
)
|
96 |
+
|
97 |
+
randomize_seed = gr.Checkbox(label="Randomize seed", value=True)
|
98 |
+
|
99 |
+
with gr.Row():
|
100 |
+
width = gr.Slider(
|
101 |
+
label="Width",
|
102 |
+
minimum=512,
|
103 |
+
maximum=MAX_IMAGE_SIZE,
|
104 |
+
step=32,
|
105 |
+
value=1024,
|
106 |
+
)
|
107 |
+
|
108 |
+
height = gr.Slider(
|
109 |
+
label="Height",
|
110 |
+
minimum=512,
|
111 |
+
maximum=MAX_IMAGE_SIZE,
|
112 |
+
step=32,
|
113 |
+
value=1024,
|
114 |
+
)
|
115 |
+
|
116 |
+
with gr.Row():
|
117 |
+
guidance_scale = gr.Slider(
|
118 |
+
label="Guidance scale",
|
119 |
+
minimum=0.0,
|
120 |
+
maximum=7.5,
|
121 |
+
step=0.1,
|
122 |
+
value=4.5,
|
123 |
+
)
|
124 |
+
|
125 |
+
num_inference_steps = gr.Slider(
|
126 |
+
label="Number of inference steps",
|
127 |
+
minimum=1,
|
128 |
+
maximum=50,
|
129 |
+
step=1,
|
130 |
+
value=40,
|
131 |
+
)
|
132 |
+
|
133 |
+
gr.Examples(examples=examples, inputs=[prompt], outputs=[result, seed], fn=infer, cache_examples=True, cache_mode="lazy")
|
134 |
+
gr.on(
|
135 |
+
triggers=[run_button.click, prompt.submit],
|
136 |
+
fn=infer,
|
137 |
+
inputs=[
|
138 |
+
prompt,
|
139 |
+
negative_prompt,
|
140 |
+
seed,
|
141 |
+
randomize_seed,
|
142 |
+
width,
|
143 |
+
height,
|
144 |
+
guidance_scale,
|
145 |
+
num_inference_steps,
|
146 |
+
],
|
147 |
+
outputs=[result, seed],
|
148 |
+
)
|
149 |
+
|
150 |
+
if __name__ == "__main__":
|
151 |
+
demo.launch()
|
requirements.txt
ADDED
@@ -0,0 +1,6 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
accelerate
|
2 |
+
diffusers
|
3 |
+
torch
|
4 |
+
transformers
|
5 |
+
git+https://github.com/huggingface/diffusers.git
|
6 |
+
sentencepiece
|