Fabrice-TIERCELIN commited on
Commit
7afda38
1 Parent(s): 8cdca89

No image writing

Browse files
Files changed (1) hide show
  1. app.py +9 -20
app.py CHANGED
@@ -19,7 +19,7 @@ def noise_color(color, noise):
19
  return color + random.randint(- noise, noise)
20
 
21
  def check(
22
- source_img,
23
  enlarge_top,
24
  enlarge_right,
25
  enlarge_bottom,
@@ -36,7 +36,7 @@ def check(
36
  seed,
37
  debug_mode,
38
  progress = gr.Progress()):
39
- if source_img is None:
40
  raise gr.Error("Please provide an image.")
41
 
42
  if prompt is None or prompt == "":
@@ -63,7 +63,7 @@ def check(
63
  raise gr.Error("At least one border must be enlarged.")
64
 
65
  def uncrop(
66
- source_img,
67
  enlarge_top,
68
  enlarge_right,
69
  enlarge_bottom,
@@ -81,7 +81,7 @@ def uncrop(
81
  debug_mode,
82
  progress = gr.Progress()):
83
  check(
84
- source_img,
85
  enlarge_top,
86
  enlarge_right,
87
  enlarge_bottom,
@@ -140,17 +140,6 @@ def uncrop(
140
  random.seed(seed)
141
  #pipe = pipe.manual_seed(seed)
142
 
143
- try:
144
- imageio.imwrite("data.png", source_img)
145
- except:
146
- raise gr.Error("Can't read input image. You can try to first save your image in another format (.webp, .png, .jpeg, .bmp...).")
147
-
148
- # Input image
149
- try:
150
- input_image = Image.open("data.png").convert("RGB")
151
- except:
152
- raise gr.Error("Can't open input image. You can try to first save your image in another format (.webp, .png, .jpeg, .bmp...).")
153
-
154
  original_height, original_width, original_channel = np.array(input_image).shape
155
  output_width = enlarge_left + original_width + enlarge_right
156
  output_height = enlarge_top + original_height + enlarge_bottom
@@ -291,7 +280,7 @@ with gr.Blocks() as interface:
291
  <li>To modify <b>anything else</b> on your image, I recommend to use <i>Instruct Pix2Pix</i>.</li>
292
  </ul>
293
  <br/>
294
- 🐌 Slow process... ~1 hour.<br>You can duplicate this space on a free account, it works on CPU.<br/>
295
  <a href='https://huggingface.co/spaces/Fabrice-TIERCELIN/Uncrop?duplicate=true'><img src='https://img.shields.io/badge/-Duplicate%20Space-blue?labelColor=white&style=flat&logo=data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAYAAAAf8/9hAAAAAXNSR0IArs4c6QAAAP5JREFUOE+lk7FqAkEURY+ltunEgFXS2sZGIbXfEPdLlnxJyDdYB62sbbUKpLbVNhyYFzbrrA74YJlh9r079973psed0cvUD4A+4HoCjsA85X0Dfn/RBLBgBDxnQPfAEJgBY+A9gALA4tcbamSzS4xq4FOQAJgCDwV2CPKV8tZAJcAjMMkUe1vX+U+SMhfAJEHasQIWmXNN3abzDwHUrgcRGmYcgKe0bxrblHEB4E/pndMazNpSZGcsZdBlYJcEL9Afo75molJyM2FxmPgmgPqlWNLGfwZGG6UiyEvLzHYDmoPkDDiNm9JR9uboiONcBXrpY1qmgs21x1QwyZcpvxt9NS09PlsPAAAAAElFTkSuQmCC&logoWidth=14'></a>
296
  <br/>
297
  ⚖️ You can use, modify and share the generated images but not for commercial uses.
@@ -309,7 +298,7 @@ with gr.Blocks() as interface:
309
  with gr.Column():
310
  enlarge_left = gr.Number(minimum = 0, value = 64, precision = 0, label = "Enlarge on left ⬅️", info = "in pixels")
311
  with gr.Column():
312
- source_img = gr.Image(label = "Your image", sources = ["upload"], type = "numpy")
313
  with gr.Column():
314
  enlarge_right = gr.Number(minimum = 0, value = 64, precision = 0, label = "Enlarge on right ➡️", info = "in pixels")
315
  with gr.Row():
@@ -353,7 +342,7 @@ with gr.Blocks() as interface:
353
  enlarged_image,
354
  mask_image
355
  ], queue = False, show_progress = False).then(check, inputs = [
356
- source_img,
357
  enlarge_top,
358
  enlarge_right,
359
  enlarge_bottom,
@@ -371,7 +360,7 @@ with gr.Blocks() as interface:
371
  debug_mode
372
  ], outputs = [], queue = False,
373
  show_progress = False).success(uncrop, inputs = [
374
- source_img,
375
  enlarge_top,
376
  enlarge_right,
377
  enlarge_bottom,
@@ -397,7 +386,7 @@ with gr.Blocks() as interface:
397
 
398
  gr.Examples(
399
  inputs = [
400
- source_img,
401
  enlarge_top,
402
  enlarge_right,
403
  enlarge_bottom,
 
19
  return color + random.randint(- noise, noise)
20
 
21
  def check(
22
+ input_image,
23
  enlarge_top,
24
  enlarge_right,
25
  enlarge_bottom,
 
36
  seed,
37
  debug_mode,
38
  progress = gr.Progress()):
39
+ if input_image is None:
40
  raise gr.Error("Please provide an image.")
41
 
42
  if prompt is None or prompt == "":
 
63
  raise gr.Error("At least one border must be enlarged.")
64
 
65
  def uncrop(
66
+ input_image,
67
  enlarge_top,
68
  enlarge_right,
69
  enlarge_bottom,
 
81
  debug_mode,
82
  progress = gr.Progress()):
83
  check(
84
+ input_image,
85
  enlarge_top,
86
  enlarge_right,
87
  enlarge_bottom,
 
140
  random.seed(seed)
141
  #pipe = pipe.manual_seed(seed)
142
 
 
 
 
 
 
 
 
 
 
 
 
143
  original_height, original_width, original_channel = np.array(input_image).shape
144
  output_width = enlarge_left + original_width + enlarge_right
145
  output_height = enlarge_top + original_height + enlarge_bottom
 
280
  <li>To modify <b>anything else</b> on your image, I recommend to use <i>Instruct Pix2Pix</i>.</li>
281
  </ul>
282
  <br/>
283
+ 🐌 Slow process... ~1 hour.<br>You can duplicate this space on a free account, it works on CPU and should also run on CUDA.<br/>
284
  <a href='https://huggingface.co/spaces/Fabrice-TIERCELIN/Uncrop?duplicate=true'><img src='https://img.shields.io/badge/-Duplicate%20Space-blue?labelColor=white&style=flat&logo=data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAYAAAAf8/9hAAAAAXNSR0IArs4c6QAAAP5JREFUOE+lk7FqAkEURY+ltunEgFXS2sZGIbXfEPdLlnxJyDdYB62sbbUKpLbVNhyYFzbrrA74YJlh9r079973psed0cvUD4A+4HoCjsA85X0Dfn/RBLBgBDxnQPfAEJgBY+A9gALA4tcbamSzS4xq4FOQAJgCDwV2CPKV8tZAJcAjMMkUe1vX+U+SMhfAJEHasQIWmXNN3abzDwHUrgcRGmYcgKe0bxrblHEB4E/pndMazNpSZGcsZdBlYJcEL9Afo75molJyM2FxmPgmgPqlWNLGfwZGG6UiyEvLzHYDmoPkDDiNm9JR9uboiONcBXrpY1qmgs21x1QwyZcpvxt9NS09PlsPAAAAAElFTkSuQmCC&logoWidth=14'></a>
285
  <br/>
286
  ⚖️ You can use, modify and share the generated images but not for commercial uses.
 
298
  with gr.Column():
299
  enlarge_left = gr.Number(minimum = 0, value = 64, precision = 0, label = "Enlarge on left ⬅️", info = "in pixels")
300
  with gr.Column():
301
+ input_image = gr.Image(label = "Your image", sources = ["upload"], type = "pil")
302
  with gr.Column():
303
  enlarge_right = gr.Number(minimum = 0, value = 64, precision = 0, label = "Enlarge on right ➡️", info = "in pixels")
304
  with gr.Row():
 
342
  enlarged_image,
343
  mask_image
344
  ], queue = False, show_progress = False).then(check, inputs = [
345
+ input_image,
346
  enlarge_top,
347
  enlarge_right,
348
  enlarge_bottom,
 
360
  debug_mode
361
  ], outputs = [], queue = False,
362
  show_progress = False).success(uncrop, inputs = [
363
+ input_image,
364
  enlarge_top,
365
  enlarge_right,
366
  enlarge_bottom,
 
386
 
387
  gr.Examples(
388
  inputs = [
389
+ input_image,
390
  enlarge_top,
391
  enlarge_right,
392
  enlarge_bottom,