michaelj commited on
Commit
424b3ed
1 Parent(s): 4f11322

change img

Browse files
Files changed (1) hide show
  1. app.py +8 -4
app.py CHANGED
@@ -17,19 +17,23 @@ pipe = pipe.to(device)
17
  pipe.load_lora_weights(adapter_id)
18
  pipe.fuse_lora()
19
 
20
- def resize(value,img):
21
  img = Image.open(img)
22
- img = img.resize((value,value))
23
  return img
24
 
25
  def infer(source_img, prompt, steps, seed, Strength):
26
  start = time.time()
 
27
  generator = torch.Generator(device).manual_seed(seed)
28
  if int(steps * Strength) < 1:
29
  steps = math.ceil(1 / max(0.10, Strength))
30
- source_image = resize(512, source_img)
 
 
 
31
  source_image.save('source.png')
32
- image = pipe(prompt, image=source_image, strength=Strength, guidance_scale=0.0, num_inference_steps=steps).images[0]
33
  end = time.time()
34
  print("步数",steps)
35
  print("时间",end-start)
 
17
  pipe.load_lora_weights(adapter_id)
18
  pipe.fuse_lora()
19
 
20
+ def resize(w,h,img):
21
  img = Image.open(img)
22
+ img = img.resize((w,h))
23
  return img
24
 
25
  def infer(source_img, prompt, steps, seed, Strength):
26
  start = time.time()
27
+ print("开始")
28
  generator = torch.Generator(device).manual_seed(seed)
29
  if int(steps * Strength) < 1:
30
  steps = math.ceil(1 / max(0.10, Strength))
31
+ w, h = source_img.size
32
+ newW = 512
33
+ newH = int(h * newW / w)
34
+ source_image = resize(newW,newH, source_img)
35
  source_image.save('source.png')
36
+ image = pipe(prompt, image=source_image,width=newW,height=newH, strength=Strength, guidance_scale=0.0, num_inference_steps=steps).images[0]
37
  end = time.time()
38
  print("步数",steps)
39
  print("时间",end-start)