JingyeChen22 commited on
Commit
c1029f2
1 Parent(s): f06d603

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +24 -1
app.py CHANGED
@@ -436,6 +436,7 @@ def to_tensor(image):
436
 
437
  import unicodedata
438
 
 
439
  def full2half(text):
440
  half = []
441
  for char in text:
@@ -448,8 +449,21 @@ def full2half(text):
448
  half.append(char)
449
  return ''.join(half)
450
 
 
 
 
 
 
 
 
 
 
451
  def text_to_image(prompt,slider_step,slider_guidance,slider_batch):
452
 
 
 
 
 
453
  prompt = full2half(prompt)
454
  prompt = prompt.replace('"', "'")
455
  prompt = prompt.replace('‘', "'")
@@ -562,6 +576,10 @@ print(f'{colored("[√]", "green")} Text segmenter is successfully loaded.')
562
 
563
  def text_to_image_with_template(prompt,template_image,slider_step,slider_guidance,slider_batch, binary):
564
 
 
 
 
 
565
  if slider_step>=50:
566
  slider_step = 50
567
 
@@ -605,7 +623,8 @@ def text_to_image_with_template(prompt,template_image,slider_step,slider_guidanc
605
  binary = gray.point(lambda x: 255 if x > 96 else 0, '1')
606
  template_image = binary.convert('RGB')
607
 
608
- # to_tensor = transforms.ToTensor()
 
609
  image_tensor = to_tensor(template_image).unsqueeze(0).cuda().sub_(0.5).div_(0.5) # (b, 3, 256, 256)
610
 
611
  with torch.no_grad():
@@ -663,6 +682,10 @@ def text_to_image_with_template(prompt,template_image,slider_step,slider_guidanc
663
 
664
  def text_inpainting(prompt,orig_image,mask_image,slider_step,slider_guidance,slider_batch):
665
 
 
 
 
 
666
  if slider_step>=50:
667
  slider_step = 50
668
 
 
436
 
437
  import unicodedata
438
 
439
+
440
  def full2half(text):
441
  half = []
442
  for char in text:
 
449
  half.append(char)
450
  return ''.join(half)
451
 
452
+ def has_chinese_char(string):
453
+ pattern = re.compile('[\u4e00-\u9fa5]')
454
+ if pattern.search(string):
455
+ return True
456
+ else:
457
+ return False
458
+
459
+ image_404 = Image.open('file/images/404.jpg')
460
+
461
  def text_to_image(prompt,slider_step,slider_guidance,slider_batch):
462
 
463
+ if has_chinese_char(prompt):
464
+ print('trigger')
465
+ return image_404, None
466
+
467
  prompt = full2half(prompt)
468
  prompt = prompt.replace('"', "'")
469
  prompt = prompt.replace('‘', "'")
 
576
 
577
  def text_to_image_with_template(prompt,template_image,slider_step,slider_guidance,slider_batch, binary):
578
 
579
+ if has_chinese_char(prompt):
580
+ print('trigger')
581
+ return image_404, None
582
+
583
  if slider_step>=50:
584
  slider_step = 50
585
 
 
623
  binary = gray.point(lambda x: 255 if x > 96 else 0, '1')
624
  template_image = binary.convert('RGB')
625
 
626
+ #
627
+ = transforms.ToTensor()
628
  image_tensor = to_tensor(template_image).unsqueeze(0).cuda().sub_(0.5).div_(0.5) # (b, 3, 256, 256)
629
 
630
  with torch.no_grad():
 
682
 
683
  def text_inpainting(prompt,orig_image,mask_image,slider_step,slider_guidance,slider_batch):
684
 
685
+ if has_chinese_char(prompt):
686
+ print('trigger')
687
+ return image_404, None
688
+
689
  if slider_step>=50:
690
  slider_step = 50
691