k-kotetsu commited on
Commit
1972fc0
·
1 Parent(s): 5e73617

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +12 -1
app.py CHANGED
@@ -9,6 +9,9 @@ from basicsr.utils.download_util import load_file_from_url
9
  from realesrgan import RealESRGANer
10
  from realesrgan.archs.srvgg_arch import SRVGGNetCompact
11
 
 
 
 
12
 
13
  last_file = None
14
  img_mode = "RGBA"
@@ -84,6 +87,11 @@ def realesrgan(img, model_name, denoise_strength, face_enhance, outscale, ext):
84
  channel_multiplier=2,
85
  bg_upsampler=upsampler)
86
 
 
 
 
 
 
87
  # Convert the input PIL image to cv2 image, so that it can be processed by realesrgan
88
  cv_img = numpy.array(img)
89
  img = cv2.cvtColor(cv_img, cv2.COLOR_RGBA2BGRA)
@@ -106,7 +114,10 @@ def realesrgan(img, model_name, denoise_strength, face_enhance, outscale, ext):
106
 
107
  #out_filename = f"output_{rnd_string(8)}.{extension}"
108
  out_filename = f"output_{rnd_string(8)}." + ext
109
- cv2.imwrite(out_filename, output)
 
 
 
110
  global last_file
111
  last_file = out_filename
112
  return out_filename
 
9
  from realesrgan import RealESRGANer
10
  from realesrgan.archs.srvgg_arch import SRVGGNetCompact
11
 
12
+ from PIL import Image
13
+ from PIL.PngImagePlugin import PngInfo
14
+
15
 
16
  last_file = None
17
  img_mode = "RGBA"
 
87
  channel_multiplier=2,
88
  bg_upsampler=upsampler)
89
 
90
+ try:
91
+ parameters = img.text['parameters']
92
+ except:
93
+ parameters = ''
94
+
95
  # Convert the input PIL image to cv2 image, so that it can be processed by realesrgan
96
  cv_img = numpy.array(img)
97
  img = cv2.cvtColor(cv_img, cv2.COLOR_RGBA2BGRA)
 
114
 
115
  #out_filename = f"output_{rnd_string(8)}.{extension}"
116
  out_filename = f"output_{rnd_string(8)}." + ext
117
+ metadata = PngInfo()
118
+ if parameters != '':
119
+ metadata.add_text("parameters", parameters)
120
+ cv2.imwrite(out_filename, output, pnginfo=metadata)
121
  global last_file
122
  last_file = out_filename
123
  return out_filename