Spaces:
Running
Running
Ubuntu
commited on
Commit
·
3678910
1
Parent(s):
ae4c73e
Added CPU support
Browse files
app.py
CHANGED
@@ -70,9 +70,15 @@ def set_example(selected_prompt):
|
|
70 |
return example["prompt"], example["ckpt"], example["aspect"], example["mode"]
|
71 |
return None, None, None, None # Default values if not found
|
72 |
|
73 |
-
#
|
74 |
-
if torch.cuda.is_available()
|
75 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
76 |
|
77 |
if SAFETY_CHECKER:
|
78 |
from safety_checker import StableDiffusionSafetyChecker
|
|
|
70 |
return example["prompt"], example["ckpt"], example["aspect"], example["mode"]
|
71 |
return None, None, None, None # Default values if not found
|
72 |
|
73 |
+
# Check if CUDA is available (GPU support), and set the appropriate device
|
74 |
+
device = "cuda" if torch.cuda.is_available() else "cpu"
|
75 |
+
|
76 |
+
# Load the pipeline for the specified device
|
77 |
+
# For GPU, use torch_dtype=torch.float16 for better performance
|
78 |
+
if device == "cuda":
|
79 |
+
pipe = StableDiffusionXLPipeline.from_pretrained(base, torch_dtype=torch.float16, variant="fp16").to(device)
|
80 |
+
else:
|
81 |
+
pipe = StableDiffusionXLPipeline.from_pretrained(base).to(device)
|
82 |
|
83 |
if SAFETY_CHECKER:
|
84 |
from safety_checker import StableDiffusionSafetyChecker
|