Shuang59 commited on
Commit
3767bc2
β€’
1 Parent(s): 5343470

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +35 -31
app.py CHANGED
@@ -298,38 +298,42 @@ def stable_diffusion_compose(prompt, scale, steps):
298
 
299
 
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
- clevr_model.to(cpu)
310
- model.to(cpu)
311
- model_up.to(cpu)
312
- pipe.to(device)
313
- return stable_diffusion_compose(prompt, guidance_scale, steps)
314
- else:
315
- pipe.to(cpu)
316
- model.to(cpu)
317
- model_up.to(cpu)
318
- clevr_model.to(device)
319
- # simple check
320
- is_text = True
321
- for char in prompt:
322
- if char.isdigit():
323
- is_text = False
324
- break
325
- if is_text:
326
- img = Image.new('RGB', (512, 512), color=(255, 255, 255))
327
- d = ImageDraw.Draw(img)
328
- font = ImageFont.load_default()
329
- d.text((0, 256), "input should be similar to the example using 2D coordinates.", fill=(0, 0, 0), font=font)
330
- return img
331
  else:
332
- return compose_clevr_objects(prompt, guidance_scale, steps)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
333
 
334
 
335
  examples_1 = 'a camel | a forest'
 
298
 
299
 
300
  def compose(prompt, version, guidance_scale, steps):
301
+ try:
302
+ with th.no_grad():
303
+ if version == 'GLIDE':
304
+ clevr_model.to(cpu)
305
+ pipe.to(cpu)
306
+ model.to(device)
307
+ model_up.to(device)
308
+ return compose_language_descriptions(prompt, guidance_scale, steps)
309
+ elif version == 'Stable_Diffusion_1v_4':
310
+ clevr_model.to(cpu)
311
+ model.to(cpu)
312
+ model_up.to(cpu)
313
+ pipe.to(device)
314
+ return stable_diffusion_compose(prompt, guidance_scale, steps)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
315
  else:
316
+ pipe.to(cpu)
317
+ model.to(cpu)
318
+ model_up.to(cpu)
319
+ clevr_model.to(device)
320
+ # simple check
321
+ is_text = True
322
+ for char in prompt:
323
+ if char.isdigit():
324
+ is_text = False
325
+ break
326
+ if is_text:
327
+ img = Image.new('RGB', (512, 512), color=(255, 255, 255))
328
+ d = ImageDraw.Draw(img)
329
+ font = ImageFont.load_default()
330
+ d.text((0, 256), "input should be similar to the example using 2D coordinates.", fill=(0, 0, 0), font=font)
331
+ return img
332
+ else:
333
+ return compose_clevr_objects(prompt, guidance_scale, steps)
334
+ except Exception as e:
335
+ print(e)
336
+ return None
337
 
338
 
339
  examples_1 = 'a camel | a forest'