Spaces:
Sleeping
Sleeping
rezaarmand
commited on
Commit
•
9ddee47
1
Parent(s):
46c6c58
Update app.py
Browse files
app.py
CHANGED
@@ -89,13 +89,14 @@ def predict(prompt, weights, seed, scale=7.5, steps=50):
|
|
89 |
try:
|
90 |
with torch.no_grad():
|
91 |
has_cuda = torch.cuda.is_available()
|
92 |
-
if has_cuda:
|
93 |
-
|
94 |
-
|
95 |
-
|
96 |
-
|
|
|
97 |
num_inference_steps=steps, weights=weights)["images"][0]
|
98 |
-
|
99 |
except Exception as e:
|
100 |
print(e)
|
101 |
return None
|
|
|
89 |
try:
|
90 |
with torch.no_grad():
|
91 |
has_cuda = torch.cuda.is_available()
|
92 |
+
with autocast('cpu' if not has_cuda else 'cuda'):
|
93 |
+
if has_cuda:
|
94 |
+
generator = torch.Generator('cuda').manual_seed(int(seed))
|
95 |
+
else:
|
96 |
+
generator = torch.Generator().manual_seed(int(seed))
|
97 |
+
image_perpneg = pipe(prompt, guidance_scale=float(scale), generator=generator,
|
98 |
num_inference_steps=steps, weights=weights)["images"][0]
|
99 |
+
return image_perpneg
|
100 |
except Exception as e:
|
101 |
print(e)
|
102 |
return None
|