Spaces:
Running
on
Zero
Running
on
Zero
Update app.py
Browse files
app.py
CHANGED
@@ -12,6 +12,9 @@ from diffusers import StableDiffusionXLPipeline, EulerAncestralDiscreteScheduler
|
|
12 |
# Create a Flask instance
|
13 |
app = Flask(__name__)
|
14 |
|
|
|
|
|
|
|
15 |
|
16 |
# Initialize model only once
|
17 |
pipe = None
|
@@ -101,7 +104,7 @@ def run():
|
|
101 |
num_images_per_prompt = data['num_images_per_prompt']
|
102 |
width = data['width'] if 'width' in data else 512 # Default width
|
103 |
height = data['height'] if 'height' in data else 512 # Default height
|
104 |
-
|
105 |
result = generate(
|
106 |
prompt,
|
107 |
negative_prompt,
|
|
|
12 |
# Create a Flask instance
|
13 |
app = Flask(__name__)
|
14 |
|
15 |
+
def clear_gpu_memory():
|
16 |
+
torch.cuda.empty_cache()
|
17 |
+
torch.cuda.synchronize()
|
18 |
|
19 |
# Initialize model only once
|
20 |
pipe = None
|
|
|
104 |
num_images_per_prompt = data['num_images_per_prompt']
|
105 |
width = data['width'] if 'width' in data else 512 # Default width
|
106 |
height = data['height'] if 'height' in data else 512 # Default height
|
107 |
+
clear_gpu_memory()
|
108 |
result = generate(
|
109 |
prompt,
|
110 |
negative_prompt,
|