Spaces:
Sleeping
Sleeping
superlazycoder
commited on
Commit
•
b3c7225
1
Parent(s):
7ac6188
Update app.py
Browse files
app.py
CHANGED
@@ -3,27 +3,24 @@ import numpy as np
|
|
3 |
import random
|
4 |
from diffusers import DiffusionPipeline
|
5 |
import torch
|
|
|
6 |
|
7 |
-
device = "cuda"
|
8 |
-
|
9 |
-
if torch.cuda.is_available():
|
10 |
-
torch.cuda.max_memory_allocated(device=device)
|
11 |
-
pipe = DiffusionPipeline.from_pretrained("stabilityai/sdxl-turbo", torch_dtype=torch.float16, variant="fp16", use_safetensors=True)
|
12 |
-
pipe.enable_xformers_memory_efficient_attention()
|
13 |
-
pipe = pipe.to(device)
|
14 |
-
else:
|
15 |
-
pipe = DiffusionPipeline.from_pretrained("stabilityai/sdxl-turbo", use_safetensors=True)
|
16 |
-
pipe = pipe.to(device)
|
17 |
|
18 |
MAX_SEED = np.iinfo(np.int32).max
|
19 |
MAX_IMAGE_SIZE = 1024
|
20 |
|
|
|
21 |
def infer(prompt, negative_prompt, seed, randomize_seed, width, height, guidance_scale, num_inference_steps):
|
22 |
|
23 |
if randomize_seed:
|
24 |
seed = random.randint(0, MAX_SEED)
|
25 |
|
26 |
generator = torch.Generator().manual_seed(seed)
|
|
|
|
|
|
|
|
|
27 |
|
28 |
image = pipe(
|
29 |
prompt = prompt,
|
@@ -50,10 +47,8 @@ css="""
|
|
50 |
}
|
51 |
"""
|
52 |
|
53 |
-
|
54 |
-
|
55 |
-
else:
|
56 |
-
power_device = "CPU"
|
57 |
|
58 |
with gr.Blocks(css=css) as demo:
|
59 |
|
|
|
3 |
import random
|
4 |
from diffusers import DiffusionPipeline
|
5 |
import torch
|
6 |
+
import spaces
|
7 |
|
8 |
+
device = "cuda"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
9 |
|
10 |
MAX_SEED = np.iinfo(np.int32).max
|
11 |
MAX_IMAGE_SIZE = 1024
|
12 |
|
13 |
+
@spaces.GPU
|
14 |
def infer(prompt, negative_prompt, seed, randomize_seed, width, height, guidance_scale, num_inference_steps):
|
15 |
|
16 |
if randomize_seed:
|
17 |
seed = random.randint(0, MAX_SEED)
|
18 |
|
19 |
generator = torch.Generator().manual_seed(seed)
|
20 |
+
|
21 |
+
pipe = DiffusionPipeline.from_pretrained("stabilityai/sdxl-turbo", torch_dtype=torch.float16, variant="fp16", use_safetensors=True)
|
22 |
+
pipe.enable_xformers_memory_efficient_attention()
|
23 |
+
pipe = pipe.to(device)
|
24 |
|
25 |
image = pipe(
|
26 |
prompt = prompt,
|
|
|
47 |
}
|
48 |
"""
|
49 |
|
50 |
+
|
51 |
+
power_device = "GPU"
|
|
|
|
|
52 |
|
53 |
with gr.Blocks(css=css) as demo:
|
54 |
|