Fabrice-TIERCELIN commited on
Commit
c7e6221
·
verified ·
1 Parent(s): 267d2a8

A little better resolution

Browse files
Files changed (1) hide show
  1. app.py +28 -13
app.py CHANGED
@@ -179,25 +179,40 @@ def uncrop(
179
  mask_image.paste(black_mask, (enlarge_left + (smooth_border // 2), enlarge_top + (smooth_border // 2)))
180
  mask_image = mask_image.filter(ImageFilter.BoxBlur((smooth_border // 2)))
181
 
182
- limitation = "";
183
-
184
  # Limited to 1 million pixels
185
  if 1024 * 1024 < output_width * output_height:
186
  factor = ((1024 * 1024) / (output_width * output_height))**0.5
187
- output_width = math.floor(output_width * factor)
188
- output_height = math.floor(output_height * factor)
189
 
190
  limitation = " Due to technical limitation, the image have been downscaled and then upscaled.";
 
 
 
 
 
191
 
192
  # Width and height must be multiple of 8
193
- output_width = output_width - (output_width % 8)
194
- output_height = output_height - (output_height % 8)
 
 
 
 
 
 
 
 
 
 
 
 
195
  progress(None, desc = "Processing...")
196
 
197
  output_image = pipe(
198
  seeds = [seed],
199
- width = output_width,
200
- height = output_height,
201
  prompt = prompt,
202
  negative_prompt = negative_prompt,
203
  image = enlarged_image,
@@ -209,7 +224,7 @@ def uncrop(
209
  ).images[0]
210
 
211
  if limitation != "":
212
- output_image = output_image.resize((enlarge_left + original_width + enlarge_right, enlarge_top + original_height + enlarge_bottom))
213
 
214
  if debug_mode == False:
215
  input_image = None
@@ -382,8 +397,8 @@ with gr.Blocks() as interface:
382
  1024,
383
  1024,
384
  1024,
385
- "An asian woman, black hair, ultrarealistic, realistic, photorealistic, 8k",
386
- "Border, frame, painting, scribbling, smear, noise, blur, watermark",
387
  20,
388
  1000,
389
  20,
@@ -399,7 +414,7 @@ with gr.Blocks() as interface:
399
  1024,
400
  1024,
401
  "Black man, jumping in the air, outside, ultrarealistic, realistic, photorealistic, 8k",
402
- "Border, frame, painting, scribbling, smear, noise, blur, watermark",
403
  20,
404
  1000,
405
  20,
@@ -415,7 +430,7 @@ with gr.Blocks() as interface:
415
  0,
416
  512,
417
  "An old yellow car, in a town, ultrarealistic, realistic, photorealistic, 8k",
418
- "Border, frame, painting, scribbling, smear, noise, blur, watermark",
419
  20,
420
  1000,
421
  20,
 
179
  mask_image.paste(black_mask, (enlarge_left + (smooth_border // 2), enlarge_top + (smooth_border // 2)))
180
  mask_image = mask_image.filter(ImageFilter.BoxBlur((smooth_border // 2)))
181
 
 
 
182
  # Limited to 1 million pixels
183
  if 1024 * 1024 < output_width * output_height:
184
  factor = ((1024 * 1024) / (output_width * output_height))**0.5
185
+ process_width = math.floor(output_width * factor)
186
+ process_height = math.floor(output_height * factor)
187
 
188
  limitation = " Due to technical limitation, the image have been downscaled and then upscaled.";
189
+ else:
190
+ process_width = output_width
191
+ process_height = output_height
192
+
193
+ limitation = "";
194
 
195
  # Width and height must be multiple of 8
196
+ if (process_width % 8) != 0 or (process_height % 8) != 0:
197
+ if ((process_width - (process_width % 8) + 8) * (process_height - (process_height % 8) + 8)) <= (1024 * 1024):
198
+ process_width = process_width - (process_width % 8) + 8
199
+ process_height = process_height - (process_height % 8) + 8
200
+ elif (process_height % 8) <= (process_width % 8) and ((process_width - (process_width % 8) + 8) * process_height) <= (1024 * 1024):
201
+ process_width = process_width - (process_width % 8) + 8
202
+ process_height = process_height - (process_height % 8)
203
+ elif (process_width % 8) <= (process_height % 8) and (process_width * (process_height - (process_height % 8) + 8)) <= (1024 * 1024):
204
+ process_width = process_width - (process_width % 8)
205
+ process_height = process_height - (process_height % 8) + 8
206
+ else:
207
+ process_width = process_width - (process_width % 8)
208
+ process_height = process_height - (process_height % 8)
209
+
210
  progress(None, desc = "Processing...")
211
 
212
  output_image = pipe(
213
  seeds = [seed],
214
+ width = process_width,
215
+ height = process_height,
216
  prompt = prompt,
217
  negative_prompt = negative_prompt,
218
  image = enlarged_image,
 
224
  ).images[0]
225
 
226
  if limitation != "":
227
+ output_image = output_image.resize((output_width, output_height))
228
 
229
  if debug_mode == False:
230
  input_image = None
 
397
  1024,
398
  1024,
399
  1024,
400
+ "An asian woman, black hair, modern wear, in the street, ultrarealistic, realistic, photorealistic, 8k",
401
+ "Border, frame, painting, drawing, cartoon, scribbling, smear, noise, blur, watermark",
402
  20,
403
  1000,
404
  20,
 
414
  1024,
415
  1024,
416
  "Black man, jumping in the air, outside, ultrarealistic, realistic, photorealistic, 8k",
417
+ "Border, frame, painting, drawing, cartoon, scribbling, smear, noise, blur, watermark",
418
  20,
419
  1000,
420
  20,
 
430
  0,
431
  512,
432
  "An old yellow car, in a town, ultrarealistic, realistic, photorealistic, 8k",
433
+ "Border, frame, painting, drawing, cartoon, scribbling, smear, noise, blur, watermark",
434
  20,
435
  1000,
436
  20,