lixiang46 commited on
Commit
0d5da93
1 Parent(s): 2990da4

fix width and height

Browse files
Files changed (1) hide show
  1. app.py +4 -19
app.py CHANGED
@@ -8,6 +8,7 @@ from kolors.models.tokenization_chatglm import ChatGLMTokenizer
8
  from diffusers import AutoencoderKL, EulerDiscreteScheduler, UNet2DConditionModel
9
  import gradio as gr
10
  import numpy as np
 
11
 
12
  device = "cuda"
13
  ckpt_dir = snapshot_download(repo_id="Kwai-Kolors/Kolors-Inpainting")
@@ -34,18 +35,17 @@ MAX_IMAGE_SIZE = 1024
34
  @spaces.GPU
35
  def infer(prompt,
36
  image,
37
- # mask_image,
38
  negative_prompt = "",
39
  seed = 0,
40
  randomize_seed = False,
41
- width = 1024,
42
- height = 1024,
43
  guidance_scale = 5.0,
44
  num_inference_steps = 25
45
  ):
46
  if randomize_seed:
47
  seed = random.randint(0, MAX_SEED)
48
  generator = torch.Generator().manual_seed(seed)
 
 
49
  result = pipe(
50
  prompt = prompt,
51
  image = image['background'],
@@ -108,21 +108,6 @@ with gr.Blocks(css=css) as Kolors:
108
  value=0,
109
  )
110
  randomize_seed = gr.Checkbox(label="Randomize seed", value=True)
111
- with gr.Row():
112
- width = gr.Slider(
113
- label="Width",
114
- minimum=256,
115
- maximum=MAX_IMAGE_SIZE,
116
- step=32,
117
- value=1024,
118
- )
119
- height = gr.Slider(
120
- label="Height",
121
- minimum=256,
122
- maximum=MAX_IMAGE_SIZE,
123
- step=32,
124
- value=1024,
125
- )
126
  with gr.Row():
127
  guidance_scale = gr.Slider(
128
  label="Guidance scale",
@@ -154,7 +139,7 @@ with gr.Blocks(css=css) as Kolors:
154
 
155
  run_button.click(
156
  fn = infer,
157
- inputs = [prompt, image, negative_prompt, seed, randomize_seed, width, height, guidance_scale, num_inference_steps],
158
  outputs = [result]
159
  )
160
 
 
8
  from diffusers import AutoencoderKL, EulerDiscreteScheduler, UNet2DConditionModel
9
  import gradio as gr
10
  import numpy as np
11
+ from PIL import Image
12
 
13
  device = "cuda"
14
  ckpt_dir = snapshot_download(repo_id="Kwai-Kolors/Kolors-Inpainting")
 
35
  @spaces.GPU
36
  def infer(prompt,
37
  image,
 
38
  negative_prompt = "",
39
  seed = 0,
40
  randomize_seed = False,
 
 
41
  guidance_scale = 5.0,
42
  num_inference_steps = 25
43
  ):
44
  if randomize_seed:
45
  seed = random.randint(0, MAX_SEED)
46
  generator = torch.Generator().manual_seed(seed)
47
+ pil_image = Image.open(image)
48
+ width, height = pil_image.size
49
  result = pipe(
50
  prompt = prompt,
51
  image = image['background'],
 
108
  value=0,
109
  )
110
  randomize_seed = gr.Checkbox(label="Randomize seed", value=True)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
111
  with gr.Row():
112
  guidance_scale = gr.Slider(
113
  label="Guidance scale",
 
139
 
140
  run_button.click(
141
  fn = infer,
142
+ inputs = [prompt, image, negative_prompt, seed, randomize_seed, guidance_scale, num_inference_steps],
143
  outputs = [result]
144
  )
145