Spaces:
Running
Running
taesd3
Browse files- README.md +2 -2
- app.py +29 -17
- requirements.txt +5 -4
README.md
CHANGED
@@ -4,10 +4,10 @@ emoji: ⚡
|
|
4 |
colorFrom: green
|
5 |
colorTo: blue
|
6 |
sdk: gradio
|
7 |
-
sdk_version: 4.
|
8 |
app_file: app.py
|
9 |
pinned: false
|
10 |
license: cc-by-nc-4.0
|
11 |
---
|
12 |
|
13 |
-
Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
|
|
|
4 |
colorFrom: green
|
5 |
colorTo: blue
|
6 |
sdk: gradio
|
7 |
+
sdk_version: 4.36.1
|
8 |
app_file: app.py
|
9 |
pinned: false
|
10 |
license: cc-by-nc-4.0
|
11 |
---
|
12 |
|
13 |
+
Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
|
app.py
CHANGED
@@ -4,7 +4,12 @@ import spaces
|
|
4 |
import gradio as gr
|
5 |
import numpy as np
|
6 |
import torch
|
7 |
-
from diffusers import
|
|
|
|
|
|
|
|
|
|
|
8 |
from peft import PeftModel
|
9 |
import os
|
10 |
from huggingface_hub import snapshot_download
|
@@ -12,16 +17,15 @@ from huggingface_hub import snapshot_download
|
|
12 |
huggingface_token = os.getenv("HUGGINFACE_TOKEN")
|
13 |
|
14 |
model_path = snapshot_download(
|
15 |
-
repo_id="stabilityai/stable-diffusion-3-medium",
|
16 |
-
|
17 |
-
repo_type="model",
|
18 |
ignore_patterns=["*.md", "*..gitattributes"],
|
19 |
local_dir="stable-diffusion-3-medium",
|
20 |
-
token=huggingface_token,
|
21 |
-
|
|
|
22 |
|
23 |
device = "cuda" if torch.cuda.is_available() else "cpu"
|
24 |
-
IS_SPACE = os.environ.get("SPACE_ID", None) is not None
|
25 |
|
26 |
transformer = SD3Transformer2DModel.from_pretrained(
|
27 |
model_path,
|
@@ -40,6 +44,10 @@ if torch.cuda.is_available():
|
|
40 |
text_encoder_3=None,
|
41 |
tokenizer_3=None,
|
42 |
)
|
|
|
|
|
|
|
|
|
43 |
|
44 |
pipe = pipe.to(device)
|
45 |
else:
|
@@ -54,9 +62,11 @@ else:
|
|
54 |
|
55 |
|
56 |
pipe.scheduler = FlashFlowMatchEulerDiscreteScheduler.from_pretrained(
|
57 |
-
|
58 |
-
|
59 |
)
|
|
|
|
|
60 |
|
61 |
MAX_SEED = np.iinfo(np.int32).max
|
62 |
MAX_IMAGE_SIZE = 1024
|
@@ -89,7 +99,7 @@ examples = [
|
|
89 |
"a cute cartoon fluffy rabbit pilot walking on a military aircraft carrier, 8k, cinematic",
|
90 |
"A 3d render of a futuristic city with a giant robot in the middle full of neon lights, pink and blue colors",
|
91 |
"A close up of an old elderly man with green eyes looking straight at the camera",
|
92 |
-
"photo of a huge red cat with green eyes sitting on a cloud in the sky, looking at the camera"
|
93 |
]
|
94 |
|
95 |
css = """
|
@@ -108,12 +118,8 @@ with gr.Blocks(css=css) as demo:
|
|
108 |
with gr.Column(elem_id="col-container"):
|
109 |
gr.Markdown(
|
110 |
f"""
|
111 |
-
# ⚡ Flash Diffusion: FlashSD3
|
112 |
-
|
113 |
-
Diffusion Model for Few Steps Image Generation](http://arxiv.org/abs/2406.02347) *by Clément Chadebec, Onur Tasar, Eyal Benaroche and Benjamin Aubin* from Jasper Research.
|
114 |
-
[This model](https://huggingface.co/jasperai/flash-sd3) is a **90.4M** LoRA distilled version of [SD3](https://huggingface.co/stabilityai/stable-diffusion-3-medium) model that is able to generate 1024x1024 images in **4 steps**.
|
115 |
-
Results can be compared with the teacher model [here](https://huggingface.co/spaces/stabilityai/stable-diffusion-3-medium).
|
116 |
-
Currently running on {power_device}.
|
117 |
"""
|
118 |
)
|
119 |
gr.Markdown(
|
@@ -154,7 +160,13 @@ with gr.Blocks(css=css) as demo:
|
|
154 |
"This demo is only for research purpose. Jasper cannot be held responsible for the generation of NSFW (Not Safe For Work) content through the use of this demo. Users are solely responsible for any content they create, and it is their obligation to ensure that it adheres to appropriate and ethical standards. Jasper provides the tools, but the responsibility for their use lies with the individual user."
|
155 |
)
|
156 |
gr.on(
|
157 |
-
[
|
|
|
|
|
|
|
|
|
|
|
|
|
158 |
fn=infer,
|
159 |
inputs=[prompt, seed, randomize_seed],
|
160 |
outputs=[result],
|
|
|
4 |
import gradio as gr
|
5 |
import numpy as np
|
6 |
import torch
|
7 |
+
from diffusers import (
|
8 |
+
StableDiffusion3Pipeline,
|
9 |
+
SD3Transformer2DModel,
|
10 |
+
FlashFlowMatchEulerDiscreteScheduler,
|
11 |
+
AutoencoderTiny,
|
12 |
+
)
|
13 |
from peft import PeftModel
|
14 |
import os
|
15 |
from huggingface_hub import snapshot_download
|
|
|
17 |
huggingface_token = os.getenv("HUGGINFACE_TOKEN")
|
18 |
|
19 |
model_path = snapshot_download(
|
20 |
+
repo_id="stabilityai/stable-diffusion-3-medium-diffusers",
|
21 |
+
repo_type="model",
|
|
|
22 |
ignore_patterns=["*.md", "*..gitattributes"],
|
23 |
local_dir="stable-diffusion-3-medium",
|
24 |
+
token=huggingface_token, # type a new token-id.
|
25 |
+
)
|
26 |
+
import spaces
|
27 |
|
28 |
device = "cuda" if torch.cuda.is_available() else "cpu"
|
|
|
29 |
|
30 |
transformer = SD3Transformer2DModel.from_pretrained(
|
31 |
model_path,
|
|
|
44 |
text_encoder_3=None,
|
45 |
tokenizer_3=None,
|
46 |
)
|
47 |
+
pipe.vae = AutoencoderTiny.from_pretrained(
|
48 |
+
"madebyollin/taesd3", torch_dtype=torch.float16
|
49 |
+
)
|
50 |
+
pipe.vae.config.shift_factor = 0.0
|
51 |
|
52 |
pipe = pipe.to(device)
|
53 |
else:
|
|
|
62 |
|
63 |
|
64 |
pipe.scheduler = FlashFlowMatchEulerDiscreteScheduler.from_pretrained(
|
65 |
+
model_path,
|
66 |
+
subfolder="scheduler",
|
67 |
)
|
68 |
+
pipe.set_progress_bar_config(disable=True)
|
69 |
+
|
70 |
|
71 |
MAX_SEED = np.iinfo(np.int32).max
|
72 |
MAX_IMAGE_SIZE = 1024
|
|
|
99 |
"a cute cartoon fluffy rabbit pilot walking on a military aircraft carrier, 8k, cinematic",
|
100 |
"A 3d render of a futuristic city with a giant robot in the middle full of neon lights, pink and blue colors",
|
101 |
"A close up of an old elderly man with green eyes looking straight at the camera",
|
102 |
+
"photo of a huge red cat with green eyes sitting on a cloud in the sky, looking at the camera",
|
103 |
]
|
104 |
|
105 |
css = """
|
|
|
118 |
with gr.Column(elem_id="col-container"):
|
119 |
gr.Markdown(
|
120 |
f"""
|
121 |
+
# ⚡ Flash Diffusion: FlashSD3 + TAESD3 ⚡️
|
122 |
+
[Flash Diffusion](https://gojasper.github.io/flash-diffusion-project/) with [Tiny AutoEncoder for Stable Diffusion 3](https://huggingface.co/madebyollin/taesd3)
|
|
|
|
|
|
|
|
|
123 |
"""
|
124 |
)
|
125 |
gr.Markdown(
|
|
|
160 |
"This demo is only for research purpose. Jasper cannot be held responsible for the generation of NSFW (Not Safe For Work) content through the use of this demo. Users are solely responsible for any content they create, and it is their obligation to ensure that it adheres to appropriate and ethical standards. Jasper provides the tools, but the responsibility for their use lies with the individual user."
|
161 |
)
|
162 |
gr.on(
|
163 |
+
[
|
164 |
+
run_button.click,
|
165 |
+
seed.change,
|
166 |
+
randomize_seed.change,
|
167 |
+
prompt.submit,
|
168 |
+
prompt.change,
|
169 |
+
],
|
170 |
fn=infer,
|
171 |
inputs=[prompt, seed, randomize_seed],
|
172 |
outputs=[result],
|
requirements.txt
CHANGED
@@ -1,14 +1,15 @@
|
|
1 |
accelerate
|
2 |
diffusers @ git+https://github.com/initml/diffusers.git@clement/feature/flash_sd3
|
3 |
invisible_watermark
|
4 |
-
--extra-index-url https://download.pytorch.org/whl/
|
5 |
-
torch
|
6 |
transformers >= 4.34.0
|
7 |
-
xformers
|
8 |
ftfy
|
9 |
spaces
|
10 |
peft >= 0.6.0
|
11 |
sentencepiece==0.2.0
|
12 |
optimum
|
13 |
beautifulsoup4
|
14 |
-
gradio==4.
|
|
|
|
1 |
accelerate
|
2 |
diffusers @ git+https://github.com/initml/diffusers.git@clement/feature/flash_sd3
|
3 |
invisible_watermark
|
4 |
+
--extra-index-url https://download.pytorch.org/whl/cu221
|
5 |
+
torch
|
6 |
transformers >= 4.34.0
|
7 |
+
# xformers
|
8 |
ftfy
|
9 |
spaces
|
10 |
peft >= 0.6.0
|
11 |
sentencepiece==0.2.0
|
12 |
optimum
|
13 |
beautifulsoup4
|
14 |
+
gradio==4.36.1
|
15 |
+
setuptools
|