Vignesh455 commited on
Commit
3379d17
·
verified ·
1 Parent(s): 40784b9

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +13 -1
app.py CHANGED
@@ -1,5 +1,7 @@
1
  import gradio as gr
2
  import torch
 
 
3
 
4
  from diffusers import AutoPipelineForInpainting, UNet2DConditionModel
5
  import diffusers
@@ -16,6 +18,14 @@ def read_content(file_path: str) -> str:
16
 
17
  return content
18
 
 
 
 
 
 
 
 
 
19
  def predict(dict, prompt="", negative_prompt="", guidance_scale=7.5, steps=30, strength=1.0, scheduler="DPMSolverMultistepScheduler-Karras"):
20
  if negative_prompt == "":
21
  negative_prompt = None
@@ -34,7 +44,9 @@ def predict(dict, prompt="", negative_prompt="", guidance_scale=7.5, steps=30, s
34
  mask = dict["mask"]
35
 
36
  output = pipe(prompt = prompt, negative_prompt=negative_prompt, image=init_image, mask_image=mask, guidance_scale=guidance_scale, num_inference_steps=int(steps), strength=strength, clip_skip=1)
37
- return output.images[0], gr.update(visible=True)
 
 
38
 
39
 
40
  css = '''
 
1
  import gradio as gr
2
  import torch
3
+ import numpy as np
4
+ from PIL import Image
5
 
6
  from diffusers import AutoPipelineForInpainting, UNet2DConditionModel
7
  import diffusers
 
18
 
19
  return content
20
 
21
+ def resize_image(img, target_shape):
22
+ """
23
+ Resize the image to the target shape while preserving aspect ratio.
24
+ """
25
+ img = Image.fromarray(img)
26
+ img = img.resize(target_shape[::-1], Image.ANTIALIAS)
27
+ return np.array(img)
28
+
29
  def predict(dict, prompt="", negative_prompt="", guidance_scale=7.5, steps=30, strength=1.0, scheduler="DPMSolverMultistepScheduler-Karras"):
30
  if negative_prompt == "":
31
  negative_prompt = None
 
44
  mask = dict["mask"]
45
 
46
  output = pipe(prompt = prompt, negative_prompt=negative_prompt, image=init_image, mask_image=mask, guidance_scale=guidance_scale, num_inference_steps=int(steps), strength=strength, clip_skip=1)
47
+ input_shape = init_image.shape[:2]
48
+ output_image = resize_image(output.images[0], input_shape)
49
+ return output_image, gr.update(visible=True)
50
 
51
 
52
  css = '''