Spaces:
Running
on
Zero
Running
on
Zero
Commit
·
5de4c7b
1
Parent(s):
f549a1f
~~
Browse files
app.py
CHANGED
@@ -57,6 +57,7 @@ def load_pipeline(model_name):
|
|
57 |
model_name,
|
58 |
torch_dtype=torch.float16,
|
59 |
custom_pipeline="lpw_stable_diffusion_xl",
|
|
|
60 |
use_safetensors=True,
|
61 |
add_watermarker=False,
|
62 |
use_auth_token=HF_TOKEN,
|
@@ -64,3 +65,50 @@ def load_pipeline(model_name):
|
|
64 |
pipe.to(device)
|
65 |
return pipe
|
66 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
57 |
model_name,
|
58 |
torch_dtype=torch.float16,
|
59 |
custom_pipeline="lpw_stable_diffusion_xl",
|
60 |
+
safety_checker = None,
|
61 |
use_safetensors=True,
|
62 |
add_watermarker=False,
|
63 |
use_auth_token=HF_TOKEN,
|
|
|
65 |
pipe.to(device)
|
66 |
return pipe
|
67 |
|
68 |
+
@spaces.GPU
|
69 |
+
def generate(
|
70 |
+
prompt: str,
|
71 |
+
negative_prompt: str = None,
|
72 |
+
seed: int = 0,
|
73 |
+
width: int = 1024,
|
74 |
+
height: int = 1024,
|
75 |
+
guidance_scale: float = 5.0,
|
76 |
+
num_inference_steps: int = 24,
|
77 |
+
sampler: str = "Euler a",
|
78 |
+
clip_skip: int = 1,
|
79 |
+
progress=gr.Progress(track_tqdm=True),
|
80 |
+
):
|
81 |
+
|
82 |
+
generator = seed_everything(seed)
|
83 |
+
pipe.scheduler = get_scheduler(pipe.scheduler.config, sampler)
|
84 |
+
pipe.text_encoder = CLIPTextModel.from_pretrained(
|
85 |
+
MODEL,
|
86 |
+
subfolder = "text_encoder",
|
87 |
+
num_hidden_layers = 12 - (clip_skip - 1),
|
88 |
+
torch_dtype = torch.float16
|
89 |
+
)
|
90 |
+
|
91 |
+
try:
|
92 |
+
|
93 |
+
img = pipe(
|
94 |
+
prompt = prompt,
|
95 |
+
negative_prompt = negative_prompt,
|
96 |
+
width = width,
|
97 |
+
height = height,
|
98 |
+
guidance_scale = guidance_scale,
|
99 |
+
num_inference_steps = num_inference_steps,
|
100 |
+
generator = generator,
|
101 |
+
output_type="pil",
|
102 |
+
).images[0]
|
103 |
+
|
104 |
+
return img
|
105 |
+
|
106 |
+
except Exception as e:
|
107 |
+
print(f"An error occurred: {e}")
|
108 |
+
|
109 |
+
if torch.cuda.is_available():
|
110 |
+
pipe = load_pipeline(MODEL)
|
111 |
+
print("Loaded on Device!")
|
112 |
+
else:
|
113 |
+
pipe = None
|
114 |
+
|