Spaces:
Running
on
Zero
Running
on
Zero
Commit
•
1e787e4
1
Parent(s):
dd6c382
Update app.py
Browse files
app.py
CHANGED
@@ -7,28 +7,9 @@ from diffusers import FluxPipeline, FluxTransformer2DModel,FlowMatchEulerDiscre
|
|
7 |
from transformers import CLIPTextModel, CLIPTokenizer,T5EncoderModel, T5TokenizerFast
|
8 |
|
9 |
dtype = torch.bfloat16
|
10 |
-
device = "cuda"
|
11 |
-
|
12 |
-
bfl_repo = "black-forest-labs/FLUX.1-dev"
|
13 |
-
scheduler = FlowMatchEulerDiscreteScheduler.from_pretrained(bfl_repo, subfolder="scheduler", revision="refs/pr/3")
|
14 |
-
text_encoder = CLIPTextModel.from_pretrained("openai/clip-vit-large-patch14", torch_dtype=dtype)
|
15 |
-
tokenizer = CLIPTokenizer.from_pretrained("openai/clip-vit-large-patch14", torch_dtype=dtype)
|
16 |
-
text_encoder_2 = T5EncoderModel.from_pretrained(bfl_repo, subfolder="text_encoder_2", torch_dtype=dtype, revision="refs/pr/3")
|
17 |
-
tokenizer_2 = T5TokenizerFast.from_pretrained(bfl_repo, subfolder="tokenizer_2", torch_dtype=dtype, revision="refs/pr/3")
|
18 |
-
vae = AutoencoderKL.from_pretrained(bfl_repo, subfolder="vae", torch_dtype=dtype, revision="refs/pr/3")
|
19 |
-
transformer = FluxTransformer2DModel.from_pretrained(bfl_repo, subfolder="transformer", torch_dtype=dtype, revision="refs/pr/3")
|
20 |
-
|
21 |
device = "cuda" if torch.cuda.is_available() else "cpu"
|
22 |
|
23 |
-
pipe = FluxPipeline(
|
24 |
-
scheduler=scheduler,
|
25 |
-
text_encoder=text_encoder,
|
26 |
-
tokenizer=tokenizer,
|
27 |
-
text_encoder_2=text_encoder_2,
|
28 |
-
tokenizer_2=tokenizer_2,
|
29 |
-
vae=vae,
|
30 |
-
transformer=transformer,
|
31 |
-
).to("cuda")
|
32 |
|
33 |
MAX_SEED = np.iinfo(np.int32).max
|
34 |
MAX_IMAGE_SIZE = 2048
|
@@ -40,12 +21,12 @@ def infer(prompt, seed=42, randomize_seed=False, width=1024, height=1024, guidan
|
|
40 |
seed = random.randint(0, MAX_SEED)
|
41 |
generator = torch.Generator().manual_seed(seed)
|
42 |
image = pipe(
|
43 |
-
|
44 |
-
|
45 |
-
|
46 |
-
|
47 |
-
|
48 |
-
|
49 |
).images[0]
|
50 |
return image, seed
|
51 |
|
|
|
7 |
from transformers import CLIPTextModel, CLIPTokenizer,T5EncoderModel, T5TokenizerFast
|
8 |
|
9 |
dtype = torch.bfloat16
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
10 |
device = "cuda" if torch.cuda.is_available() else "cpu"
|
11 |
|
12 |
+
pipe = FluxPipeline.from_pretrained("black-forest-labs/FLUX.1-dev", torch_dtype=torch.bfloat16).to(device)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
13 |
|
14 |
MAX_SEED = np.iinfo(np.int32).max
|
15 |
MAX_IMAGE_SIZE = 2048
|
|
|
21 |
seed = random.randint(0, MAX_SEED)
|
22 |
generator = torch.Generator().manual_seed(seed)
|
23 |
image = pipe(
|
24 |
+
prompt = prompt,
|
25 |
+
width = width,
|
26 |
+
height = height,
|
27 |
+
num_inference_steps = num_inference_steps,
|
28 |
+
generator = generator,
|
29 |
+
guidance_scale=guidance_scale
|
30 |
).images[0]
|
31 |
return image, seed
|
32 |
|