Spaces:
Running
on
Zero
Running
on
Zero
Commit
•
8ccf632
1
Parent(s):
f51fcb8
Create app.py
Browse files
app.py
ADDED
@@ -0,0 +1,123 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import gradio as gr
|
2 |
+
import numpy as np
|
3 |
+
import random
|
4 |
+
import spaces
|
5 |
+
from diffusers import AuraFlowPipeline
|
6 |
+
import torch
|
7 |
+
|
8 |
+
device = "cuda" if torch.cuda.is_available() else "cpu"
|
9 |
+
|
10 |
+
pipe = AuraFlowPipeline.from_pretrained(
|
11 |
+
"fal/AuraFlow-v0.2",
|
12 |
+
torch_dtype=torch.float16
|
13 |
+
).to("cuda")
|
14 |
+
|
15 |
+
MAX_SEED = np.iinfo(np.int32).max
|
16 |
+
MAX_IMAGE_SIZE = 1024
|
17 |
+
|
18 |
+
@spaces.GPU()
|
19 |
+
def infer(prompt, seed=42, randomize_seed=False, width=1024, height=1024, num_inference_steps=4, progress=gr.Progress(track_tqdm=True)):
|
20 |
+
generator = torch.Generator().manual_seed(seed)
|
21 |
+
image = pipe(
|
22 |
+
prompt = prompt,
|
23 |
+
width = width,
|
24 |
+
height = height,
|
25 |
+
num_inference_steps = num_inference_steps,
|
26 |
+
generator = generator
|
27 |
+
).images[0]
|
28 |
+
return image, seed
|
29 |
+
|
30 |
+
examples = [
|
31 |
+
"A photo of a lavender cat",
|
32 |
+
"Astronaut in a jungle, cold color palette, muted colors, detailed, 8k",
|
33 |
+
"An astronaut riding a green horse",
|
34 |
+
"A delicious ceviche cheesecake slice",
|
35 |
+
]
|
36 |
+
|
37 |
+
css="""
|
38 |
+
#col-container {
|
39 |
+
margin: 0 auto;
|
40 |
+
max-width: 520px;
|
41 |
+
}
|
42 |
+
"""
|
43 |
+
|
44 |
+
with gr.Blocks(css=css) as demo:
|
45 |
+
|
46 |
+
with gr.Column(elem_id="col-container"):
|
47 |
+
gr.Markdown(f"""
|
48 |
+
# FLUX.1 Schnell
|
49 |
+
Demo of the [FLUX.1 Schnell](https://huggingface.co/fal/AuraFlow) 12B parameters rectified flow transformer distilled from [FLUX.1 Pro](https://blackforestlabs.ai/) for fast generation in 4 steps
|
50 |
+
[[blog](https://blackforestlabs.ai/2024/07/31/announcing-black-forest-labs/)] [[model](https://black-forest-labs/FLUX.1-schnell)]]
|
51 |
+
""")
|
52 |
+
|
53 |
+
with gr.Row():
|
54 |
+
|
55 |
+
prompt = gr.Text(
|
56 |
+
label="Prompt",
|
57 |
+
show_label=False,
|
58 |
+
max_lines=1,
|
59 |
+
placeholder="Enter your prompt",
|
60 |
+
container=False,
|
61 |
+
)
|
62 |
+
|
63 |
+
run_button = gr.Button("Run", scale=0)
|
64 |
+
|
65 |
+
result = gr.Image(label="Result", show_label=False)
|
66 |
+
|
67 |
+
with gr.Accordion("Advanced Settings", open=False):
|
68 |
+
|
69 |
+
seed = gr.Slider(
|
70 |
+
label="Seed",
|
71 |
+
minimum=0,
|
72 |
+
maximum=MAX_SEED,
|
73 |
+
step=1,
|
74 |
+
value=0,
|
75 |
+
)
|
76 |
+
|
77 |
+
randomize_seed = gr.Checkbox(label="Randomize seed", value=True)
|
78 |
+
|
79 |
+
with gr.Row():
|
80 |
+
|
81 |
+
width = gr.Slider(
|
82 |
+
label="Width",
|
83 |
+
minimum=256,
|
84 |
+
maximum=MAX_IMAGE_SIZE,
|
85 |
+
step=32,
|
86 |
+
value=1024,
|
87 |
+
)
|
88 |
+
|
89 |
+
height = gr.Slider(
|
90 |
+
label="Height",
|
91 |
+
minimum=256,
|
92 |
+
maximum=MAX_IMAGE_SIZE,
|
93 |
+
step=32,
|
94 |
+
value=1024,
|
95 |
+
)
|
96 |
+
|
97 |
+
with gr.Row():
|
98 |
+
|
99 |
+
|
100 |
+
num_inference_steps = gr.Slider(
|
101 |
+
label="Number of inference steps",
|
102 |
+
minimum=1,
|
103 |
+
maximum=50,
|
104 |
+
step=1,
|
105 |
+
value=4,
|
106 |
+
)
|
107 |
+
|
108 |
+
gr.Examples(
|
109 |
+
examples = examples,
|
110 |
+
fn = infer_example,
|
111 |
+
inputs = [prompt],
|
112 |
+
outputs = [result, seed],
|
113 |
+
cache_examples="lazy"
|
114 |
+
)
|
115 |
+
|
116 |
+
gr.on(
|
117 |
+
triggers=[run_button.click, prompt.submit, negative_prompt.submit],
|
118 |
+
fn = infer,
|
119 |
+
inputs = [prompt, seed, randomize_seed, width, height, num_inference_steps],
|
120 |
+
outputs = [result, seed]
|
121 |
+
)
|
122 |
+
|
123 |
+
demo.queue().launch()
|