Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
|
@@ -34,14 +34,14 @@ from diffusers import StableDiffusionPipeline
|
|
| 34 |
# On a GPU, it should be under a minute.
|
| 35 |
|
| 36 |
has_cuda = False
|
| 37 |
-
|
| 38 |
cpu = th.device('cpu')
|
| 39 |
|
| 40 |
# iniatilize stable diffusion model
|
| 41 |
pipe = StableDiffusionPipeline.from_pretrained(
|
| 42 |
"CompVis/stable-diffusion-v1-4",
|
| 43 |
use_auth_token='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'
|
| 44 |
-
).to(
|
| 45 |
|
| 46 |
# Create base model.
|
| 47 |
timestep_respacing = 100 # @param{type: 'number'}
|
|
@@ -77,7 +77,6 @@ def show_images(batch: th.Tensor):
|
|
| 77 |
|
| 78 |
|
| 79 |
def compose_language_descriptions(prompt, guidance_scale, steps):
|
| 80 |
-
device = th.device('cpu')
|
| 81 |
options['timestep_respacing'] = str(steps)
|
| 82 |
_, diffusion = create_model_and_diffusion(**options)
|
| 83 |
|
|
@@ -245,7 +244,6 @@ print('total clevr_pos parameters', sum(x.numel() for x in clevr_model.parameter
|
|
| 245 |
|
| 246 |
|
| 247 |
def compose_clevr_objects(prompt, guidance_scale, steps):
|
| 248 |
-
device = th.device('cpu')
|
| 249 |
coordinates = [[float(x.split(',')[0].strip()), float(x.split(',')[1].strip())]
|
| 250 |
for x in prompt.split('|')]
|
| 251 |
coordinates += [[-1, -1]] # add unconditional score label
|
|
@@ -302,10 +300,22 @@ def stable_diffusion_compose(prompt, scale, steps):
|
|
| 302 |
def compose(prompt, version, guidance_scale, steps):
|
| 303 |
with th.no_grad():
|
| 304 |
if version == 'GLIDE':
|
|
|
|
|
|
|
|
|
|
|
|
|
| 305 |
return compose_language_descriptions(prompt, guidance_scale, steps)
|
| 306 |
elif version == 'Stable_Diffusion_1v_4':
|
|
|
|
|
|
|
|
|
|
|
|
|
| 307 |
return stable_diffusion_compose(prompt, guidance_scale, steps)
|
| 308 |
else:
|
|
|
|
|
|
|
|
|
|
|
|
|
| 309 |
return compose_clevr_objects(prompt, guidance_scale, steps)
|
| 310 |
|
| 311 |
|
|
|
|
| 34 |
# On a GPU, it should be under a minute.
|
| 35 |
|
| 36 |
has_cuda = False
|
| 37 |
+
device = th.device('cpu' if not th.cuda.is_available() else 'cuda')
|
| 38 |
cpu = th.device('cpu')
|
| 39 |
|
| 40 |
# iniatilize stable diffusion model
|
| 41 |
pipe = StableDiffusionPipeline.from_pretrained(
|
| 42 |
"CompVis/stable-diffusion-v1-4",
|
| 43 |
use_auth_token='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'
|
| 44 |
+
).to(cpu)
|
| 45 |
|
| 46 |
# Create base model.
|
| 47 |
timestep_respacing = 100 # @param{type: 'number'}
|
|
|
|
| 77 |
|
| 78 |
|
| 79 |
def compose_language_descriptions(prompt, guidance_scale, steps):
|
|
|
|
| 80 |
options['timestep_respacing'] = str(steps)
|
| 81 |
_, diffusion = create_model_and_diffusion(**options)
|
| 82 |
|
|
|
|
| 244 |
|
| 245 |
|
| 246 |
def compose_clevr_objects(prompt, guidance_scale, steps):
|
|
|
|
| 247 |
coordinates = [[float(x.split(',')[0].strip()), float(x.split(',')[1].strip())]
|
| 248 |
for x in prompt.split('|')]
|
| 249 |
coordinates += [[-1, -1]] # add unconditional score label
|
|
|
|
| 300 |
def compose(prompt, version, guidance_scale, steps):
|
| 301 |
with th.no_grad():
|
| 302 |
if version == 'GLIDE':
|
| 303 |
+
clevr_model.to(cpu)
|
| 304 |
+
pipe.to(cpu)
|
| 305 |
+
model.to(device)
|
| 306 |
+
model_up.to(device)
|
| 307 |
return compose_language_descriptions(prompt, guidance_scale, steps)
|
| 308 |
elif version == 'Stable_Diffusion_1v_4':
|
| 309 |
+
model.to(cpu)
|
| 310 |
+
model_up.to(cpu)
|
| 311 |
+
clevr_model.to(cpu)
|
| 312 |
+
pipe.to(device)
|
| 313 |
return stable_diffusion_compose(prompt, guidance_scale, steps)
|
| 314 |
else:
|
| 315 |
+
model.to(cpu)
|
| 316 |
+
model_up.to(cpu)
|
| 317 |
+
pipe.to(cpu)
|
| 318 |
+
clevr_model.to(device)
|
| 319 |
return compose_clevr_objects(prompt, guidance_scale, steps)
|
| 320 |
|
| 321 |
|