michaelj commited on
Commit
735cac1
1 Parent(s): 5e47e5a
Files changed (1) hide show
  1. app.py +19 -5
app.py CHANGED
@@ -23,10 +23,24 @@ device = "cuda" if torch.cuda.is_available() else "cpu"
23
  # helper.enable()
24
  # pipe.compile()
25
 
26
- def resize(value,img):
27
- img = Image.open(img)
28
- img = img.resize((value,value))
29
- return img
 
 
 
 
 
 
 
 
 
 
 
 
 
 
30
 
31
  def infer(model_id,source_img, prompt, steps, seed, Strength):
32
  pipe = OVStableDiffusionImg2ImgPipeline.from_pretrained(model_id, torch_dtype=torch.float16, export=True) if torch.cuda.is_available() else AutoPipelineForImage2Image.from_pretrained("stabilityai/sdxl-turbo")
@@ -48,7 +62,7 @@ def infer(model_id,source_img, prompt, steps, seed, Strength):
48
  return image
49
 
50
  gr.Interface(fn=infer, inputs=[
51
- gr.Text(value="Lykon/dreamshaper-xl-v2-turbo", label="Checkpoint"),
52
  gr.Image(sources=["upload", "webcam", "clipboard"], type="filepath", label="Raw Image."),
53
  gr.Textbox(label = 'Prompt Input Text. 77 Token (Keyword or Symbol) Maximum'),
54
  gr.Slider(1, 5, value = 2, step = 1, label = 'Number of Iterations'),
 
23
  # helper.enable()
24
  # pipe.compile()
25
 
26
+ def resize(target_size,source):
27
+ original_width,original_height =source.size
28
+ aspect_ratio = original_height / original_width
29
+
30
+ # 计算新的高度以保持宽高比,假设我们先确定宽度为512像素
31
+ new_width = target_size
32
+ new_height = int(new_width*aspect_ratio)
33
+
34
+ # 如果新高度超过目标大小,则重新计算宽度以保持目标高度
35
+ if new_height > target_size:
36
+ new_height = target_size
37
+ new_width = int(new_height / aspect_ratio)
38
+ print("宽高",original_height,original_width,aspect_ratio,new_height)
39
+ # 等比例缩放图片
40
+ # resized_image = Image.fromarray(image_array).resize((new_width, new_height), resample=Image.LANCZOS)
41
+ resized_image =source.resize((new_width, new_height))
42
+ return resized_image
43
+
44
 
45
  def infer(model_id,source_img, prompt, steps, seed, Strength):
46
  pipe = OVStableDiffusionImg2ImgPipeline.from_pretrained(model_id, torch_dtype=torch.float16, export=True) if torch.cuda.is_available() else AutoPipelineForImage2Image.from_pretrained("stabilityai/sdxl-turbo")
 
62
  return image
63
 
64
  gr.Interface(fn=infer, inputs=[
65
+ gr.Text(value="IDKiro/sdxs-512-dreamshaper", label="Checkpoint"),
66
  gr.Image(sources=["upload", "webcam", "clipboard"], type="filepath", label="Raw Image."),
67
  gr.Textbox(label = 'Prompt Input Text. 77 Token (Keyword or Symbol) Maximum'),
68
  gr.Slider(1, 5, value = 2, step = 1, label = 'Number of Iterations'),