acmyu commited on
Commit
7aba721
·
1 Parent(s): b2507e6

image resize api

Browse files
Files changed (2) hide show
  1. app.py +6 -1
  2. main.py +10 -5
app.py CHANGED
@@ -1,4 +1,4 @@
1
- from main import run_app, run_train, run_inference, run_generate_frame, run_interpolate_frames
2
  from evaluate import run_evaluate, get_score
3
 
4
  import spaces
@@ -33,6 +33,7 @@ with gr.Blocks() as demo:
33
  interp_btn = gr.Button(value="Interpolate Frames")
34
  eval_btn = gr.Button(value="Evaluate All")
35
  eval_btn2 = gr.Button(value="Evaluate")
 
36
  with gr.Column():
37
  animation = gr.Video(label="Result")
38
  frames = gr.Gallery(type="pil", label="Frames", format="png")
@@ -68,6 +69,10 @@ with gr.Blocks() as demo:
68
  eval_btn2.click(
69
  get_score, inputs=[name, char_imgs, mocap, tr_steps, inf_steps, fps, remove_bg], outputs=[eval_scores]
70
  )
 
 
 
 
71
 
72
 
73
  demo.launch(share=True, show_error=True)
 
1
+ from main import run_app, run_train, run_inference, run_generate_frame, run_interpolate_frames, resize_images
2
  from evaluate import run_evaluate, get_score
3
 
4
  import spaces
 
33
  interp_btn = gr.Button(value="Interpolate Frames")
34
  eval_btn = gr.Button(value="Evaluate All")
35
  eval_btn2 = gr.Button(value="Evaluate")
36
+ resize_btn = gr.Button(value="Resize")
37
  with gr.Column():
38
  animation = gr.Video(label="Result")
39
  frames = gr.Gallery(type="pil", label="Frames", format="png")
 
69
  eval_btn2.click(
70
  get_score, inputs=[name, char_imgs, mocap, tr_steps, inf_steps, fps, remove_bg], outputs=[eval_scores]
71
  )
72
+
73
+ resize_btn.click(
74
+ resize_images, inputs=[frame_imgs, img_width, img_height], outputs=[frames]
75
+ )
76
 
77
 
78
  demo.launch(share=True, show_error=True)
main.py CHANGED
@@ -184,8 +184,7 @@ def img_pad(img, tw, th, transparent=False):
184
  return new_img
185
 
186
 
187
- def resize_and_pad(img, target_img):
188
- tw, th = target_img.size
189
  w, h = img.size
190
 
191
  if tw/th > w/h:
@@ -195,9 +194,12 @@ def resize_and_pad(img, target_img):
195
 
196
  img = img.resize((tw, th), Image.BICUBIC)
197
 
198
- tw, th = target_img.size
199
 
200
- return img_pad(img, tw, th)
 
 
 
201
 
202
 
203
  def remove_zero_pad(image):
@@ -1329,7 +1331,10 @@ def run_interpolate_frames(frame1, frame2, times_to_interp, remove_bg):
1329
  return results[0]
1330
 
1331
 
1332
-
 
 
 
1333
 
1334
 
1335
 
 
184
  return new_img
185
 
186
 
187
+ def resize_pad(img, tw, th, transparent):
 
188
  w, h = img.size
189
 
190
  if tw/th > w/h:
 
194
 
195
  img = img.resize((tw, th), Image.BICUBIC)
196
 
197
+ return img_pad(img, tw, th, transparent)
198
 
199
+
200
+ def resize_and_pad(img, target_img):
201
+ tw, th = target_img.size
202
+ return resize_pad(img, tw, th, False)
203
 
204
 
205
  def remove_zero_pad(image):
 
1331
  return results[0]
1332
 
1333
 
1334
+ def resize_images(images, width, height):
1335
+ images = [img[0] for img in images]
1336
+ return [resize_pad(img, width, height, True) for img in images]
1337
+
1338
 
1339
 
1340