Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
|
@@ -6,7 +6,7 @@ import numpy as np
|
|
| 6 |
|
| 7 |
import random
|
| 8 |
import torch
|
| 9 |
-
from diffusers import StableDiffusion3Pipeline, AutoencoderKL, StableDiffusionXLImg2ImgPipeline,
|
| 10 |
from transformers import AutoTokenizer, AutoModelForCausalLM, TextIteratorStreamer
|
| 11 |
from threading import Thread
|
| 12 |
from transformers import pipeline
|
|
@@ -55,14 +55,14 @@ checkpoint = "microsoft/Phi-3.5-mini-instruct"
|
|
| 55 |
#vae = AutoencoderKL.from_pretrained("madebyollin/sdxl-vae-fp16-fix", torch_dtype=torch.float16)
|
| 56 |
vae = AutoencoderKL.from_pretrained("ford442/sdxl-vae-bf16", torch_dtype=torch.bfloat16, device_map='balanced')
|
| 57 |
|
| 58 |
-
pipe = StableDiffusion3Pipeline.from_pretrained("ford442/stable-diffusion-3.5-medium-bf16", torch_dtype=torch.bfloat16
|
| 59 |
#pipe = StableDiffusion3Pipeline.from_pretrained("stabilityai/stable-diffusion-3.5-medium", token=hftoken, torch_dtype=torch.float32, device_map='balanced')
|
| 60 |
|
| 61 |
# pipe.scheduler = DPMSolverMultistepScheduler.from_config(pipe.scheduler.config, use_karras_sigmas=True, algorithm_type="sde-dpmsolver++")
|
| 62 |
|
| 63 |
#pipe.scheduler.config.requires_aesthetics_score = False
|
| 64 |
#pipe.enable_model_cpu_offload()
|
| 65 |
-
|
| 66 |
#pipe = torch.compile(pipe)
|
| 67 |
# pipe.scheduler = EulerAncestralDiscreteScheduler.from_config(pipe.scheduler.config, beta_schedule="scaled_linear")
|
| 68 |
|
|
@@ -90,7 +90,7 @@ def filter_text(text):
|
|
| 90 |
MAX_SEED = np.iinfo(np.int32).max
|
| 91 |
MAX_IMAGE_SIZE = 4096
|
| 92 |
|
| 93 |
-
@spaces.GPU(duration=
|
| 94 |
def infer(
|
| 95 |
prompt,
|
| 96 |
negative_prompt,
|
|
@@ -139,7 +139,8 @@ def infer(
|
|
| 139 |
print('-- filtered prompt --')
|
| 140 |
print(enhanced_prompt)
|
| 141 |
print('-- generating image --')
|
| 142 |
-
|
|
|
|
| 143 |
prompt=enhanced_prompt, # This conversion is fine
|
| 144 |
negative_prompt=negative_prompt,
|
| 145 |
guidance_scale=guidance_scale,
|
|
@@ -147,7 +148,7 @@ def infer(
|
|
| 147 |
width=width,
|
| 148 |
height=height,
|
| 149 |
generator=generator
|
| 150 |
-
|
| 151 |
print('-- got image --')
|
| 152 |
image_path = f"sd35m_{seed}.png"
|
| 153 |
sd_image.save(image_path,optimize=False,compress_level=0)
|
|
|
|
| 6 |
|
| 7 |
import random
|
| 8 |
import torch
|
| 9 |
+
from diffusers import StableDiffusion3Pipeline, AutoencoderKL, StableDiffusionXLImg2ImgPipeline, EulerAncestralDiscreteScheduler
|
| 10 |
from transformers import AutoTokenizer, AutoModelForCausalLM, TextIteratorStreamer
|
| 11 |
from threading import Thread
|
| 12 |
from transformers import pipeline
|
|
|
|
| 55 |
#vae = AutoencoderKL.from_pretrained("madebyollin/sdxl-vae-fp16-fix", torch_dtype=torch.float16)
|
| 56 |
vae = AutoencoderKL.from_pretrained("ford442/sdxl-vae-bf16", torch_dtype=torch.bfloat16, device_map='balanced')
|
| 57 |
|
| 58 |
+
pipe = StableDiffusion3Pipeline.from_pretrained("ford442/stable-diffusion-3.5-medium-bf16", torch_dtype=torch.bfloat16)
|
| 59 |
#pipe = StableDiffusion3Pipeline.from_pretrained("stabilityai/stable-diffusion-3.5-medium", token=hftoken, torch_dtype=torch.float32, device_map='balanced')
|
| 60 |
|
| 61 |
# pipe.scheduler = DPMSolverMultistepScheduler.from_config(pipe.scheduler.config, use_karras_sigmas=True, algorithm_type="sde-dpmsolver++")
|
| 62 |
|
| 63 |
#pipe.scheduler.config.requires_aesthetics_score = False
|
| 64 |
#pipe.enable_model_cpu_offload()
|
| 65 |
+
pipe.to(device)
|
| 66 |
#pipe = torch.compile(pipe)
|
| 67 |
# pipe.scheduler = EulerAncestralDiscreteScheduler.from_config(pipe.scheduler.config, beta_schedule="scaled_linear")
|
| 68 |
|
|
|
|
| 90 |
MAX_SEED = np.iinfo(np.int32).max
|
| 91 |
MAX_IMAGE_SIZE = 4096
|
| 92 |
|
| 93 |
+
@spaces.GPU(duration=90)
|
| 94 |
def infer(
|
| 95 |
prompt,
|
| 96 |
negative_prompt,
|
|
|
|
| 139 |
print('-- filtered prompt --')
|
| 140 |
print(enhanced_prompt)
|
| 141 |
print('-- generating image --')
|
| 142 |
+
with torch.no_grad():
|
| 143 |
+
sd_image = pipe(
|
| 144 |
prompt=enhanced_prompt, # This conversion is fine
|
| 145 |
negative_prompt=negative_prompt,
|
| 146 |
guidance_scale=guidance_scale,
|
|
|
|
| 148 |
width=width,
|
| 149 |
height=height,
|
| 150 |
generator=generator
|
| 151 |
+
).images[0]
|
| 152 |
print('-- got image --')
|
| 153 |
image_path = f"sd35m_{seed}.png"
|
| 154 |
sd_image.save(image_path,optimize=False,compress_level=0)
|