Spaces:
Running
on
Zero
Running
on
Zero
added fluxx schnell
Browse files- app.py +35 -39
- requirements.txt +2 -1
app.py
CHANGED
@@ -1,27 +1,24 @@
|
|
1 |
import gradio as gr
|
2 |
import numpy as np
|
3 |
import random
|
4 |
-
|
5 |
-
# import spaces #[uncomment to use ZeroGPU]
|
6 |
from diffusers import DiffusionPipeline
|
7 |
import torch
|
8 |
|
9 |
device = "cuda" if torch.cuda.is_available() else "cpu"
|
10 |
-
model_repo_id = "black-forest-labs/FLUX.1-schnell"
|
11 |
|
12 |
-
if torch.cuda.is_available()
|
13 |
-
torch_dtype = torch.float16
|
14 |
-
else:
|
15 |
-
torch_dtype = torch.float32
|
16 |
|
17 |
-
|
18 |
-
pipe =
|
|
|
|
|
|
|
|
|
19 |
|
20 |
MAX_SEED = np.iinfo(np.int32).max
|
21 |
MAX_IMAGE_SIZE = 1024
|
22 |
|
23 |
-
|
24 |
-
# @spaces.GPU #[uncomment to use ZeroGPU]
|
25 |
def infer(
|
26 |
prompt,
|
27 |
negative_prompt,
|
@@ -36,20 +33,22 @@ def infer(
|
|
36 |
if randomize_seed:
|
37 |
seed = random.randint(0, MAX_SEED)
|
38 |
|
39 |
-
|
40 |
-
|
41 |
-
|
42 |
-
|
43 |
-
|
44 |
-
|
45 |
-
|
46 |
-
|
47 |
-
|
48 |
-
|
49 |
-
|
50 |
-
|
51 |
-
|
52 |
-
|
|
|
|
|
53 |
|
54 |
examples = [
|
55 |
"Astronaut in a jungle, cold color palette, muted colors, detailed, 8k",
|
@@ -66,27 +65,25 @@ css = """
|
|
66 |
|
67 |
with gr.Blocks(css=css) as demo:
|
68 |
with gr.Column(elem_id="col-container"):
|
69 |
-
gr.Markdown("
|
70 |
|
71 |
with gr.Row():
|
72 |
-
prompt = gr.
|
73 |
label="Prompt",
|
74 |
show_label=False,
|
75 |
max_lines=1,
|
76 |
placeholder="Enter your prompt",
|
77 |
container=False,
|
78 |
)
|
|
|
79 |
|
80 |
-
|
81 |
-
|
82 |
-
result = gr.Image(label="Result", show_label=False)
|
83 |
|
84 |
with gr.Accordion("Advanced Settings", open=False):
|
85 |
-
negative_prompt = gr.
|
86 |
label="Negative prompt",
|
87 |
max_lines=1,
|
88 |
placeholder="Enter a negative prompt",
|
89 |
-
visible=False,
|
90 |
)
|
91 |
|
92 |
seed = gr.Slider(
|
@@ -105,15 +102,14 @@ with gr.Blocks(css=css) as demo:
|
|
105 |
minimum=256,
|
106 |
maximum=MAX_IMAGE_SIZE,
|
107 |
step=32,
|
108 |
-
value=1024,
|
109 |
)
|
110 |
-
|
111 |
height = gr.Slider(
|
112 |
label="Height",
|
113 |
minimum=256,
|
114 |
maximum=MAX_IMAGE_SIZE,
|
115 |
step=32,
|
116 |
-
value=1024,
|
117 |
)
|
118 |
|
119 |
with gr.Row():
|
@@ -122,18 +118,18 @@ with gr.Blocks(css=css) as demo:
|
|
122 |
minimum=0.0,
|
123 |
maximum=10.0,
|
124 |
step=0.1,
|
125 |
-
value=
|
126 |
)
|
127 |
-
|
128 |
num_inference_steps = gr.Slider(
|
129 |
label="Number of inference steps",
|
130 |
minimum=1,
|
131 |
maximum=50,
|
132 |
step=1,
|
133 |
-
value=
|
134 |
)
|
135 |
|
136 |
gr.Examples(examples=examples, inputs=[prompt])
|
|
|
137 |
gr.on(
|
138 |
triggers=[run_button.click, prompt.submit],
|
139 |
fn=infer,
|
@@ -151,4 +147,4 @@ with gr.Blocks(css=css) as demo:
|
|
151 |
)
|
152 |
|
153 |
if __name__ == "__main__":
|
154 |
-
demo.launch()
|
|
|
1 |
import gradio as gr
|
2 |
import numpy as np
|
3 |
import random
|
|
|
|
|
4 |
from diffusers import DiffusionPipeline
|
5 |
import torch
|
6 |
|
7 |
device = "cuda" if torch.cuda.is_available() else "cpu"
|
8 |
+
model_repo_id = "black-forest-labs/FLUX.1-schnell"
|
9 |
|
10 |
+
torch_dtype = torch.float16 if torch.cuda.is_available() else torch.float32
|
|
|
|
|
|
|
11 |
|
12 |
+
try:
|
13 |
+
pipe = DiffusionPipeline.from_pretrained(model_repo_id, torch_dtype=torch_dtype)
|
14 |
+
pipe = pipe.to(device)
|
15 |
+
except Exception as e:
|
16 |
+
print(f"Error loading model: {e}")
|
17 |
+
raise
|
18 |
|
19 |
MAX_SEED = np.iinfo(np.int32).max
|
20 |
MAX_IMAGE_SIZE = 1024
|
21 |
|
|
|
|
|
22 |
def infer(
|
23 |
prompt,
|
24 |
negative_prompt,
|
|
|
33 |
if randomize_seed:
|
34 |
seed = random.randint(0, MAX_SEED)
|
35 |
|
36 |
+
try:
|
37 |
+
generator = torch.Generator(device=device).manual_seed(seed)
|
38 |
+
|
39 |
+
image = pipe(
|
40 |
+
prompt=prompt,
|
41 |
+
negative_prompt=negative_prompt,
|
42 |
+
guidance_scale=guidance_scale,
|
43 |
+
num_inference_steps=num_inference_steps,
|
44 |
+
width=width,
|
45 |
+
height=height,
|
46 |
+
generator=generator,
|
47 |
+
).images[0]
|
48 |
+
|
49 |
+
return image, seed
|
50 |
+
except Exception as e:
|
51 |
+
raise gr.Error(f"Generation failed: {str(e)}")
|
52 |
|
53 |
examples = [
|
54 |
"Astronaut in a jungle, cold color palette, muted colors, detailed, 8k",
|
|
|
65 |
|
66 |
with gr.Blocks(css=css) as demo:
|
67 |
with gr.Column(elem_id="col-container"):
|
68 |
+
gr.Markdown("# Text-to-Image Generation")
|
69 |
|
70 |
with gr.Row():
|
71 |
+
prompt = gr.Textbox(
|
72 |
label="Prompt",
|
73 |
show_label=False,
|
74 |
max_lines=1,
|
75 |
placeholder="Enter your prompt",
|
76 |
container=False,
|
77 |
)
|
78 |
+
run_button = gr.Button("Generate", scale=0, variant="primary")
|
79 |
|
80 |
+
result = gr.Image(label="Generated Image", show_label=True)
|
|
|
|
|
81 |
|
82 |
with gr.Accordion("Advanced Settings", open=False):
|
83 |
+
negative_prompt = gr.Textbox(
|
84 |
label="Negative prompt",
|
85 |
max_lines=1,
|
86 |
placeholder="Enter a negative prompt",
|
|
|
87 |
)
|
88 |
|
89 |
seed = gr.Slider(
|
|
|
102 |
minimum=256,
|
103 |
maximum=MAX_IMAGE_SIZE,
|
104 |
step=32,
|
105 |
+
value=1024,
|
106 |
)
|
|
|
107 |
height = gr.Slider(
|
108 |
label="Height",
|
109 |
minimum=256,
|
110 |
maximum=MAX_IMAGE_SIZE,
|
111 |
step=32,
|
112 |
+
value=1024,
|
113 |
)
|
114 |
|
115 |
with gr.Row():
|
|
|
118 |
minimum=0.0,
|
119 |
maximum=10.0,
|
120 |
step=0.1,
|
121 |
+
value=7.5,
|
122 |
)
|
|
|
123 |
num_inference_steps = gr.Slider(
|
124 |
label="Number of inference steps",
|
125 |
minimum=1,
|
126 |
maximum=50,
|
127 |
step=1,
|
128 |
+
value=20,
|
129 |
)
|
130 |
|
131 |
gr.Examples(examples=examples, inputs=[prompt])
|
132 |
+
|
133 |
gr.on(
|
134 |
triggers=[run_button.click, prompt.submit],
|
135 |
fn=infer,
|
|
|
147 |
)
|
148 |
|
149 |
if __name__ == "__main__":
|
150 |
+
demo.launch(share=True)
|
requirements.txt
CHANGED
@@ -3,4 +3,5 @@ diffusers
|
|
3 |
invisible_watermark
|
4 |
torch
|
5 |
transformers
|
6 |
-
xformers
|
|
|
|
3 |
invisible_watermark
|
4 |
torch
|
5 |
transformers
|
6 |
+
xformers
|
7 |
+
sentencepiece
|