Fabrice-TIERCELIN commited on
Commit
4a997df
·
verified ·
1 Parent(s): 5ac2897
Files changed (1) hide show
  1. app.py +47 -16
app.py CHANGED
@@ -4,6 +4,7 @@ import time
4
  import math
5
  import random
6
  import torch
 
7
 
8
  from diffusers import StableDiffusionXLInpaintPipeline
9
  from PIL import Image, ImageFilter
@@ -232,21 +233,20 @@ def uncrop(
232
 
233
  progress(None, desc = "Processing...")
234
 
235
- output_image = pipe(
236
- seeds = [seed],
237
- width = process_width,
238
- height = process_height,
239
- prompt = prompt,
240
- negative_prompt = negative_prompt,
241
- image = enlarged_image,
242
- mask_image = mask_image,
243
- num_inference_steps = num_inference_steps,
244
- guidance_scale = guidance_scale,
245
- image_guidance_scale = image_guidance_scale,
246
- strength = strength,
247
- denoising_steps = denoising_steps,
248
- show_progress_bar = True
249
- ).images[0]
250
 
251
  if limitation != "":
252
  output_image = output_image.resize((output_width, output_height))
@@ -270,6 +270,36 @@ def uncrop(
270
  mask_image
271
  ]
272
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
273
  with gr.Blocks() as interface:
274
  gr.HTML(
275
  """
@@ -289,7 +319,8 @@ with gr.Blocks() as interface:
289
  <li>To modify <b>anything else</b> on your image, I recommend to use <i>Instruct Pix2Pix</i>.</li>
290
  </ul>
291
  <br/>
292
- 🐌 Slow process... ~1 hour. Your computer must <u>not</u> enter into standby mode.<br/>You can duplicate this space on a free account, it works on CPU and should also run on CUDA.<br/>
 
293
  <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>
294
  <br/>
295
  ⚖️ You can use, modify and share the generated images but not for commercial uses.
 
4
  import math
5
  import random
6
  import torch
7
+ import spaces
8
 
9
  from diffusers import StableDiffusionXLInpaintPipeline
10
  from PIL import Image, ImageFilter
 
233
 
234
  progress(None, desc = "Processing...")
235
 
236
+ output_image = uncrop_on_gpu(
237
+ seed,
238
+ process_width,
239
+ process_height,
240
+ prompt,
241
+ negative_prompt,
242
+ enlarged_image,
243
+ mask_image,
244
+ num_inference_steps,
245
+ guidance_scale,
246
+ image_guidance_scale,
247
+ strength,
248
+ denoising_steps
249
+ )
 
250
 
251
  if limitation != "":
252
  output_image = output_image.resize((output_width, output_height))
 
270
  mask_image
271
  ]
272
 
273
+ @spaces.GPU(duration=420)
274
+ def uncrop_on_gpu(
275
+ seed,
276
+ process_width,
277
+ process_height,
278
+ prompt,
279
+ negative_prompt,
280
+ enlarged_image,
281
+ mask_image,
282
+ num_inference_steps,
283
+ guidance_scale,
284
+ image_guidance_scale,
285
+ strength,
286
+ denoising_steps):
287
+ return pipe(
288
+ seeds = [seed],
289
+ width = process_width,
290
+ height = process_height,
291
+ prompt = prompt,
292
+ negative_prompt = negative_prompt,
293
+ image = enlarged_image,
294
+ mask_image = mask_image,
295
+ num_inference_steps = num_inference_steps,
296
+ guidance_scale = guidance_scale,
297
+ image_guidance_scale = image_guidance_scale,
298
+ strength = strength,
299
+ denoising_steps = denoising_steps,
300
+ show_progress_bar = True
301
+ ).images[0]
302
+
303
  with gr.Blocks() as interface:
304
  gr.HTML(
305
  """
 
319
  <li>To modify <b>anything else</b> on your image, I recommend to use <i>Instruct Pix2Pix</i>.</li>
320
  </ul>
321
  <br/>
322
+ """ + ("🏃‍♀️ Estimated time: few minutes." if torch.cuda.is_available() else "🐌 Slow process... ~1 hour.") + """
323
+ Your computer must <u>not</u> enter into standby mode.<br/>You can duplicate this space on a free account, it's designed to work on CPU, GPU and ZeroGPU.<br/>
324
  <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>
325
  <br/>
326
  ⚖️ You can use, modify and share the generated images but not for commercial uses.