fffiloni commited on
Commit
3dbde48
1 Parent(s): 594539b

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +15 -1
app.py CHANGED
@@ -70,7 +70,21 @@ preprocess = weights.transforms()
70
  resnet = resnet50(weights=weights)
71
  resnet.eval()
72
 
 
 
 
 
 
 
 
 
 
 
 
 
 
73
  def inference(input_image, prompt, a_prompt, n_prompt, denoise_steps, upscale, alpha, cfg, seed):
 
74
  process_size = 768
75
  resize_preproc = transforms.Compose([
76
  transforms.Resize(process_size, interpolation=transforms.InterpolationMode.BILINEAR),
@@ -155,7 +169,7 @@ with gr.Blocks(css=css) as demo:
155
  """)
156
  with gr.Row():
157
  with gr.Column():
158
- input_image = gr.Image(type="pil", sources=["upload"], value="samples/frog.png")
159
  prompt_in = gr.Textbox(label="Prompt", value="Frog")
160
  with gr.Accordion(label="Advanced settings", open=False):
161
  added_prompt = gr.Textbox(label="Added Prompt", value='clean, high-resolution, 8k, best quality, masterpiece')
 
70
  resnet = resnet50(weights=weights)
71
  resnet.eval()
72
 
73
+ def resize_image(image_path, target_height):
74
+ # Open the image file
75
+ with Image.open(image_path) as img:
76
+ # Calculate the ratio to resize the image to the target height
77
+ ratio = target_height / float(img.size[1])
78
+ # Calculate the new width based on the aspect ratio
79
+ new_width = int(float(img.size[0]) * ratio)
80
+ # Resize the image
81
+ resized_img = img.resize((new_width, target_height), Image.LANCZOS)
82
+ # Save the resized image
83
+ #resized_img.save(output_path)
84
+ return resized_img
85
+
86
  def inference(input_image, prompt, a_prompt, n_prompt, denoise_steps, upscale, alpha, cfg, seed):
87
+ input_image = resize_image(input_image, 256)
88
  process_size = 768
89
  resize_preproc = transforms.Compose([
90
  transforms.Resize(process_size, interpolation=transforms.InterpolationMode.BILINEAR),
 
169
  """)
170
  with gr.Row():
171
  with gr.Column():
172
+ input_image = gr.Image(type="filepath", sources=["upload"], value="samples/frog.png")
173
  prompt_in = gr.Textbox(label="Prompt", value="Frog")
174
  with gr.Accordion(label="Advanced settings", open=False):
175
  added_prompt = gr.Textbox(label="Added Prompt", value='clean, high-resolution, 8k, best quality, masterpiece')