jbilcke-hf commited on
Commit
6136894
·
1 Parent(s): aaa160e

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +20 -18
app.py CHANGED
@@ -93,23 +93,25 @@ preprocess = weights.transforms()
93
  resnet = resnet50(weights=weights)
94
  resnet.eval()
95
 
96
- def resize_image(image_path, target_height):
97
- # Open the image file
98
- with Image.open(image_path) as img:
99
- # Calculate the ratio to resize the image to the target height
100
- ratio = target_height / float(img.size[1])
101
- # Calculate the new width based on the aspect ratio
102
- new_width = int(float(img.size[0]) * ratio)
103
- # Resize the image
104
- resized_img = img.resize((new_width, target_height), Image.LANCZOS)
105
- # Save the resized image
106
- #resized_img.save(output_path)
107
- return resized_img
108
 
109
  # @spaces.GPU(enable_queue=True)
110
- def inference(input_image, prompt, a_prompt, n_prompt, denoise_steps, upscale, alpha, cfg, seed):
111
- input_image = resize_image(input_image, 512)
 
 
 
112
  process_size = 768
 
113
  resize_preproc = transforms.Compose([
114
  transforms.Resize(process_size, interpolation=transforms.InterpolationMode.BILINEAR),
115
  ])
@@ -171,7 +173,7 @@ with gr.Blocks() as demo:
171
  with gr.Column():
172
  with gr.Row():
173
  with gr.Column():
174
- input_image = gr.Textbox()
175
  prompt_in = gr.Textbox(label="Prompt", value="Frog")
176
  with gr.Accordion(label="Advanced settings", open=False):
177
  added_prompt = gr.Textbox(label="Added Prompt", value='clean, high-resolution, 8k, best quality, masterpiece')
@@ -183,17 +185,17 @@ with gr.Blocks() as demo:
183
  seed = gr.Slider(label="Seed", minimum=-1, maximum=2147483647, step=1, randomize=True)
184
  submit_btn = gr.Button("Submit")
185
  with gr.Column():
186
- output_image = gr.Textbox()
187
 
188
  submit_btn.click(
189
  fn = inference,
190
  inputs = [
191
- input_image, prompt_in,
192
  added_prompt, neg_prompt,
193
  denoise_steps,
194
  upsample_scale, condition_scale,
195
  classifier_free_guidance, seed
196
  ],
197
- outputs = output_image
198
  )
199
  demo.queue().launch()
 
93
  resnet = resnet50(weights=weights)
94
  resnet.eval()
95
 
96
+ def resize_image(img, target_height):
97
+ # Calculate the ratio to resize the image to the target height
98
+ ratio = target_height / float(img.size[1])
99
+ # Calculate the new width based on the aspect ratio
100
+ new_width = int(float(img.size[0]) * ratio)
101
+ # Resize the image
102
+ resized_img = img.resize((new_width, target_height), Image.LANCZOS)
103
+ # Save the resized image
104
+ #resized_img.save(output_path)
105
+ return resized_img
 
 
106
 
107
  # @spaces.GPU(enable_queue=True)
108
+ def inference(input_image_b64, prompt, a_prompt, n_prompt, denoise_steps, upscale, alpha, cfg, seed):
109
+ input_image = readb64(input_image_b64)
110
+
111
+ input_image = resize_image(input, 512)
112
+
113
  process_size = 768
114
+
115
  resize_preproc = transforms.Compose([
116
  transforms.Resize(process_size, interpolation=transforms.InterpolationMode.BILINEAR),
117
  ])
 
173
  with gr.Column():
174
  with gr.Row():
175
  with gr.Column():
176
+ input_image_b64 = gr.Textbox()
177
  prompt_in = gr.Textbox(label="Prompt", value="Frog")
178
  with gr.Accordion(label="Advanced settings", open=False):
179
  added_prompt = gr.Textbox(label="Added Prompt", value='clean, high-resolution, 8k, best quality, masterpiece')
 
185
  seed = gr.Slider(label="Seed", minimum=-1, maximum=2147483647, step=1, randomize=True)
186
  submit_btn = gr.Button("Submit")
187
  with gr.Column():
188
+ output_image_b64 = gr.Textbox()
189
 
190
  submit_btn.click(
191
  fn = inference,
192
  inputs = [
193
+ input_image_b64, prompt_in,
194
  added_prompt, neg_prompt,
195
  denoise_steps,
196
  upsample_scale, condition_scale,
197
  classifier_free_guidance, seed
198
  ],
199
+ outputs = output_image_b64
200
  )
201
  demo.queue().launch()