Spaces:
Runtime error
Runtime error
change img
Browse files
app.py
CHANGED
|
@@ -18,20 +18,21 @@ pipe.load_lora_weights(adapter_id)
|
|
| 18 |
pipe.fuse_lora()
|
| 19 |
|
| 20 |
def resize(w,h,img):
|
| 21 |
-
|
| 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 =
|
| 32 |
newW = 512
|
| 33 |
newH = int(h * newW / w)
|
| 34 |
-
source_image = resize(newW,newH,
|
| 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()
|
|
|
|
| 18 |
pipe.fuse_lora()
|
| 19 |
|
| 20 |
def resize(w,h,img):
|
| 21 |
+
|
| 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 |
+
img = Image.open(source_img)
|
| 29 |
generator = torch.Generator(device).manual_seed(seed)
|
| 30 |
if int(steps * Strength) < 1:
|
| 31 |
steps = math.ceil(1 / max(0.10, Strength))
|
| 32 |
+
w, h = img.size
|
| 33 |
newW = 512
|
| 34 |
newH = int(h * newW / w)
|
| 35 |
+
source_image = resize(newW,newH, img)
|
| 36 |
source_image.save('source.png')
|
| 37 |
image = pipe(prompt, image=source_image,width=newW,height=newH, strength=Strength, guidance_scale=0.0, num_inference_steps=steps).images[0]
|
| 38 |
end = time.time()
|