Spaces:
Runtime error
Runtime error
cocktailpeanut
commited on
Commit
•
dc637a5
1
Parent(s):
89275cd
update
Browse files
app.py
CHANGED
@@ -7,11 +7,16 @@ import math
|
|
7 |
#import spaces
|
8 |
import torch
|
9 |
from PIL import Image
|
|
|
10 |
|
11 |
if torch.backends.mps.is_available():
|
12 |
DEVICE = "mps"
|
|
|
|
|
13 |
elif torch.cuda.is_available():
|
14 |
DEVICE = "cuda"
|
|
|
|
|
15 |
else:
|
16 |
DEVICE = "cpu"
|
17 |
|
@@ -60,7 +65,14 @@ def run_edit(image, prompt, resolution, negative_prompt="", guidance_scale=7, pr
|
|
60 |
#image.resize((resolution, resolution))
|
61 |
#return pipe_edit(prompt=prompt,image=image,height=resolution,width=resolution,negative_prompt=negative_prompt, guidance_scale=guidance_scale,num_inference_steps=20).images[0]
|
62 |
print(f"width={image.width}, height={image.height}")
|
63 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
64 |
css = '''
|
65 |
.gradio-container{
|
66 |
max-width: 768px !important;
|
|
|
7 |
#import spaces
|
8 |
import torch
|
9 |
from PIL import Image
|
10 |
+
import gc
|
11 |
|
12 |
if torch.backends.mps.is_available():
|
13 |
DEVICE = "mps"
|
14 |
+
torch.mps.empty_cache()
|
15 |
+
gc.collect()
|
16 |
elif torch.cuda.is_available():
|
17 |
DEVICE = "cuda"
|
18 |
+
torch.cuda.empty_cache()
|
19 |
+
gc.collect()
|
20 |
else:
|
21 |
DEVICE = "cpu"
|
22 |
|
|
|
65 |
#image.resize((resolution, resolution))
|
66 |
#return pipe_edit(prompt=prompt,image=image,height=resolution,width=resolution,negative_prompt=negative_prompt, guidance_scale=guidance_scale,num_inference_steps=20).images[0]
|
67 |
print(f"width={image.width}, height={image.height}")
|
68 |
+
img = pipe_edit(prompt=prompt,image=image,height=image.height,width=image.width,negative_prompt=negative_prompt, guidance_scale=guidance_scale,num_inference_steps=20).images[0]
|
69 |
+
if DEVICE == "cuda":
|
70 |
+
torch.cuda.empty_cache()
|
71 |
+
gc.collect()
|
72 |
+
elif DEVICE == "mps":
|
73 |
+
torch.mps.empty_cache()
|
74 |
+
gc.collect()
|
75 |
+
return img
|
76 |
css = '''
|
77 |
.gradio-container{
|
78 |
max-width: 768px !important;
|