Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
@@ -1,22 +1,31 @@
|
|
1 |
import gradio as gr
|
2 |
-
|
|
|
3 |
|
4 |
# Load the model
|
5 |
-
|
|
|
6 |
|
7 |
def generate_image(prompt):
|
8 |
-
|
9 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
10 |
return image
|
11 |
|
12 |
-
# Create the
|
13 |
-
|
14 |
-
|
15 |
-
|
16 |
-
|
17 |
-
title="FLUX.1-dev Image
|
18 |
-
description="
|
19 |
)
|
20 |
|
21 |
-
# Launch the
|
22 |
-
|
|
|
1 |
import gradio as gr
|
2 |
+
import torch
|
3 |
+
from diffusers import FluxPipeline
|
4 |
|
5 |
# Load the model
|
6 |
+
pipe = FluxPipeline.from_pretrained("black-forest-labs/FLUX.1-dev", torch_dtype=torch.bfloat16)
|
7 |
+
pipe.enable_model_cpu_offload() #save some VRAM by offloading the model to CPU. Remove this if you have enough GPU power
|
8 |
|
9 |
def generate_image(prompt):
|
10 |
+
image = pipe(
|
11 |
+
prompt,
|
12 |
+
height=1024,
|
13 |
+
width=1024,
|
14 |
+
guidance_scale=3.5,
|
15 |
+
num_inference_steps=50,
|
16 |
+
max_sequence_length=512,
|
17 |
+
generator=torch.Generator("cpu").manual_seed(0)
|
18 |
+
).images[0]
|
19 |
return image
|
20 |
|
21 |
+
# Create the UI
|
22 |
+
ui = gr.Interface(
|
23 |
+
generate_image,
|
24 |
+
gr.Textbox(lines=2, placeholder="Enter your prompt here..."),
|
25 |
+
"image",
|
26 |
+
title="FLUX.1-dev Image Generator",
|
27 |
+
description="Generate images using the FLUX.1-dev model.",
|
28 |
)
|
29 |
|
30 |
+
# Launch the UI
|
31 |
+
ui.launch()
|