Spaces:
Runtime error
Runtime error
cocktailpeanut
commited on
Commit
•
49bc296
1
Parent(s):
d424d18
update
Browse files- app.py +25 -23
- requirements.txt +4 -4
app.py
CHANGED
@@ -1,5 +1,5 @@
|
|
1 |
import random
|
2 |
-
import spaces
|
3 |
|
4 |
import gradio as gr
|
5 |
import numpy as np
|
@@ -7,8 +7,10 @@ import torch
|
|
7 |
from diffusers import LCMScheduler, PixArtAlphaPipeline, Transformer2DModel
|
8 |
from peft import PeftModel
|
9 |
import os
|
|
|
10 |
|
11 |
-
device =
|
|
|
12 |
IS_SPACE = os.environ.get("SPACE_ID", None) is not None
|
13 |
|
14 |
transformer = Transformer2DModel.from_pretrained(
|
@@ -50,7 +52,7 @@ MAX_IMAGE_SIZE = 1024
|
|
50 |
NUM_INFERENCE_STEPS = 4
|
51 |
|
52 |
|
53 |
-
|
54 |
def infer(prompt, seed, randomize_seed):
|
55 |
if randomize_seed:
|
56 |
seed = random.randint(0, MAX_SEED)
|
@@ -86,29 +88,29 @@ css = """
|
|
86 |
}
|
87 |
"""
|
88 |
|
89 |
-
if torch.cuda.is_available():
|
90 |
-
power_device = "GPU"
|
91 |
-
else:
|
92 |
-
power_device = "CPU"
|
93 |
|
94 |
with gr.Blocks(css=css) as demo:
|
95 |
with gr.Column(elem_id="col-container"):
|
96 |
-
gr.Markdown(
|
97 |
-
f"""
|
98 |
-
# ⚡ Flash Diffusion: FlashPixart ⚡
|
99 |
-
This is an interactive demo of [Flash Diffusion](https://gojasper.github.io/flash-diffusion-project/), a diffusion distillation method proposed in [Flash Diffusion: Accelerating Any Conditional
|
100 |
-
Diffusion Model for Few Steps Image Generation](http://arxiv.org/abs/2406.02347) *by Clément Chadebec, Onur Tasar, Eyal Benaroche and Benjamin Aubin.*
|
101 |
-
[This model](https://huggingface.co/jasperai/flash-pixart) is a **66.5M** LoRA distilled version of [Pixart-α](https://huggingface.co/PixArt-alpha/PixArt-XL-2-1024-MS) model that is able to generate 1024x1024 images in **4 steps**.
|
102 |
-
Currently running on {power_device}.
|
103 |
-
"""
|
104 |
-
)
|
105 |
-
gr.Markdown(
|
106 |
-
"If you enjoy the space, please also promote *open-source* by giving a ⭐ to the <a href='https://github.com/gojasper/flash-diffusion' target='_blank'>Github Repo</a>."
|
107 |
-
)
|
108 |
-
gr.Markdown(
|
109 |
-
"💡 *Hint:* To better appreciate the low latency of our method, run the demo locally !"
|
110 |
-
)
|
111 |
-
|
112 |
with gr.Row():
|
113 |
prompt = gr.Text(
|
114 |
label="Prompt",
|
|
|
1 |
import random
|
2 |
+
#import spaces
|
3 |
|
4 |
import gradio as gr
|
5 |
import numpy as np
|
|
|
7 |
from diffusers import LCMScheduler, PixArtAlphaPipeline, Transformer2DModel
|
8 |
from peft import PeftModel
|
9 |
import os
|
10 |
+
import devicetorch
|
11 |
|
12 |
+
device = devicetorch.get(torch)
|
13 |
+
#device = "cuda" if torch.cuda.is_available() else "cpu"
|
14 |
IS_SPACE = os.environ.get("SPACE_ID", None) is not None
|
15 |
|
16 |
transformer = Transformer2DModel.from_pretrained(
|
|
|
52 |
NUM_INFERENCE_STEPS = 4
|
53 |
|
54 |
|
55 |
+
#@spaces.GPU
|
56 |
def infer(prompt, seed, randomize_seed):
|
57 |
if randomize_seed:
|
58 |
seed = random.randint(0, MAX_SEED)
|
|
|
88 |
}
|
89 |
"""
|
90 |
|
91 |
+
#if torch.cuda.is_available():
|
92 |
+
# power_device = "GPU"
|
93 |
+
#else:
|
94 |
+
# power_device = "CPU"
|
95 |
|
96 |
with gr.Blocks(css=css) as demo:
|
97 |
with gr.Column(elem_id="col-container"):
|
98 |
+
# gr.Markdown(
|
99 |
+
# f"""
|
100 |
+
# # ⚡ Flash Diffusion: FlashPixart ⚡
|
101 |
+
# This is an interactive demo of [Flash Diffusion](https://gojasper.github.io/flash-diffusion-project/), a diffusion distillation method proposed in [Flash Diffusion: Accelerating Any Conditional
|
102 |
+
# Diffusion Model for Few Steps Image Generation](http://arxiv.org/abs/2406.02347) *by Clément Chadebec, Onur Tasar, Eyal Benaroche and Benjamin Aubin.*
|
103 |
+
# [This model](https://huggingface.co/jasperai/flash-pixart) is a **66.5M** LoRA distilled version of [Pixart-α](https://huggingface.co/PixArt-alpha/PixArt-XL-2-1024-MS) model that is able to generate 1024x1024 images in **4 steps**.
|
104 |
+
# Currently running on {power_device}.
|
105 |
+
# """
|
106 |
+
# )
|
107 |
+
# gr.Markdown(
|
108 |
+
# "If you enjoy the space, please also promote *open-source* by giving a ⭐ to the <a href='https://github.com/gojasper/flash-diffusion' target='_blank'>Github Repo</a>."
|
109 |
+
# )
|
110 |
+
# gr.Markdown(
|
111 |
+
# "💡 *Hint:* To better appreciate the low latency of our method, run the demo locally !"
|
112 |
+
# )
|
113 |
+
#
|
114 |
with gr.Row():
|
115 |
prompt = gr.Text(
|
116 |
label="Prompt",
|
requirements.txt
CHANGED
@@ -1,13 +1,13 @@
|
|
1 |
accelerate
|
2 |
git+https://github.com/huggingface/diffusers/
|
3 |
invisible_watermark
|
4 |
-
|
5 |
-
torch==2.0.1
|
6 |
peft >= 0.6.0
|
7 |
sentencepiece==0.2.0
|
8 |
optimum
|
9 |
beautifulsoup4
|
10 |
transformers >= 4.34.0
|
11 |
-
xformers
|
12 |
ftfy
|
13 |
-
spaces
|
|
|
1 |
accelerate
|
2 |
git+https://github.com/huggingface/diffusers/
|
3 |
invisible_watermark
|
4 |
+
#--extra-index-url https://download.pytorch.org/whl/cu118
|
5 |
+
#torch==2.0.1
|
6 |
peft >= 0.6.0
|
7 |
sentencepiece==0.2.0
|
8 |
optimum
|
9 |
beautifulsoup4
|
10 |
transformers >= 4.34.0
|
11 |
+
#xformers
|
12 |
ftfy
|
13 |
+
#spaces
|