Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -4,7 +4,7 @@ import random
|
|
| 4 |
import os
|
| 5 |
|
| 6 |
# import spaces #[uncomment to use ZeroGPU]
|
| 7 |
-
from diffusers import AutoPipelineForText2Image
|
| 8 |
import torch
|
| 9 |
|
| 10 |
device = "cuda" if torch.cuda.is_available() else "cpu"
|
|
@@ -12,11 +12,14 @@ hf_token = os.getenv('HF_TOKEN')
|
|
| 12 |
|
| 13 |
if torch.cuda.is_available():
|
| 14 |
torch_dtype = torch.float16
|
|
|
|
| 15 |
else:
|
| 16 |
torch_dtype = torch.float32
|
| 17 |
|
|
|
|
| 18 |
pipe = pipeline = AutoPipelineForText2Image.from_pretrained("black-forest-labs/FLUX.1-dev", token=hf_token, torch_dtype=torch.bfloat16)
|
| 19 |
pipe.load_lora_weights('aleksa-codes/flux-ghibsky-illustration', weight_name='lora.safetensors')
|
|
|
|
| 20 |
pipe = pipe.to(device)
|
| 21 |
|
| 22 |
MAX_SEED = np.iinfo(np.int32).max
|
|
@@ -26,13 +29,12 @@ MAX_IMAGE_SIZE = 1024
|
|
| 26 |
# @spaces.GPU #[uncomment to use ZeroGPU]
|
| 27 |
def infer(
|
| 28 |
prompt,
|
| 29 |
-
|
| 30 |
-
|
| 31 |
-
|
| 32 |
-
|
| 33 |
-
|
| 34 |
-
|
| 35 |
-
num_inference_steps,
|
| 36 |
progress=gr.Progress(track_tqdm=True),
|
| 37 |
):
|
| 38 |
if randomize_seed:
|
|
@@ -42,12 +44,12 @@ def infer(
|
|
| 42 |
|
| 43 |
image = pipe(
|
| 44 |
prompt=prompt,
|
| 45 |
-
negative_prompt=negative_prompt,
|
| 46 |
guidance_scale=guidance_scale,
|
| 47 |
num_inference_steps=num_inference_steps,
|
| 48 |
width=width,
|
| 49 |
height=height,
|
| 50 |
generator=generator,
|
|
|
|
| 51 |
).images[0]
|
| 52 |
|
| 53 |
return image, seed
|
|
|
|
| 4 |
import os
|
| 5 |
|
| 6 |
# import spaces #[uncomment to use ZeroGPU]
|
| 7 |
+
from diffusers import AutoPipelineForText2Image, AutoencoderKL, AutoencoderTiny
|
| 8 |
import torch
|
| 9 |
|
| 10 |
device = "cuda" if torch.cuda.is_available() else "cpu"
|
|
|
|
| 12 |
|
| 13 |
if torch.cuda.is_available():
|
| 14 |
torch_dtype = torch.float16
|
| 15 |
+
torch.cuda.empty_cache()
|
| 16 |
else:
|
| 17 |
torch_dtype = torch.float32
|
| 18 |
|
| 19 |
+
taef1 = AutoencoderTiny.from_pretrained("madebyollin/taef1", torch_dtype=dtype).to(device)
|
| 20 |
pipe = pipeline = AutoPipelineForText2Image.from_pretrained("black-forest-labs/FLUX.1-dev", token=hf_token, torch_dtype=torch.bfloat16)
|
| 21 |
pipe.load_lora_weights('aleksa-codes/flux-ghibsky-illustration', weight_name='lora.safetensors')
|
| 22 |
+
good_vae = AutoencoderKL.from_pretrained("black-forest-labs/FLUX.1-dev", subfolder="vae", torch_dtype=dtype).to(device)
|
| 23 |
pipe = pipe.to(device)
|
| 24 |
|
| 25 |
MAX_SEED = np.iinfo(np.int32).max
|
|
|
|
| 29 |
# @spaces.GPU #[uncomment to use ZeroGPU]
|
| 30 |
def infer(
|
| 31 |
prompt,
|
| 32 |
+
seed=42,
|
| 33 |
+
randomize_seed=True,
|
| 34 |
+
width=1024,
|
| 35 |
+
height=1024,
|
| 36 |
+
guidance_scale=3.5,
|
| 37 |
+
num_inference_steps=28,
|
|
|
|
| 38 |
progress=gr.Progress(track_tqdm=True),
|
| 39 |
):
|
| 40 |
if randomize_seed:
|
|
|
|
| 44 |
|
| 45 |
image = pipe(
|
| 46 |
prompt=prompt,
|
|
|
|
| 47 |
guidance_scale=guidance_scale,
|
| 48 |
num_inference_steps=num_inference_steps,
|
| 49 |
width=width,
|
| 50 |
height=height,
|
| 51 |
generator=generator,
|
| 52 |
+
good_vae=good_vae,
|
| 53 |
).images[0]
|
| 54 |
|
| 55 |
return image, seed
|