yizhangliu commited on
Commit
c4a39f9
1 Parent(s): aecd865

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +10 -5
app.py CHANGED
@@ -2,15 +2,14 @@ import gradio as gr
2
  from PIL import Image
3
  import numpy as np
4
  import os,sys
5
- import uuid
6
  import torch
7
  import cv2
 
8
 
9
  import io
10
  import multiprocessing
11
  import random
12
  import time
13
- import imghdr
14
  from loguru import logger
15
 
16
  from share_btn import community_icon_html, loading_icon_html, share_js
@@ -168,8 +167,14 @@ def model_process(image, mask, img_enhancer):
168
  log_info = f"image_enhancer_: {(time.time() - start) * 1000}ms, {res_np_img.shape} "
169
  logger.info(log_info)
170
 
171
- return image # image
172
 
 
 
 
 
 
 
173
  model = ModelManager(
174
  name='lama',
175
  device=device,
@@ -192,7 +197,7 @@ def predict(input, img_enhancer):
192
  image = np.array(image_pil)
193
  mask = np.array(mask_pil.convert("L"))
194
  output = model_process(image, mask, img_enhancer)
195
- return output, [image_pil, output], gr.update(visible=True)
196
 
197
  css = '''
198
  .container {max-width: 1150px; margin: auto;padding-top: 1.5rem}
@@ -411,4 +416,4 @@ with image_blocks as demo:
411
 
412
  begin_button.click(fn=None, inputs=[], outputs=[group_1, group_2], _js=start_cleaner)
413
 
414
- image_blocks.launch(server_name='0.0.0.0')
 
2
  from PIL import Image
3
  import numpy as np
4
  import os,sys
 
5
  import torch
6
  import cv2
7
+ import base64
8
 
9
  import io
10
  import multiprocessing
11
  import random
12
  import time
 
13
  from loguru import logger
14
 
15
  from share_btn import community_icon_html, loading_icon_html, share_js
 
167
  log_info = f"image_enhancer_: {(time.time() - start) * 1000}ms, {res_np_img.shape} "
168
  logger.info(log_info)
169
 
170
+ return image
171
 
172
+ def resize_image(pil_image, new_width=400):
173
+ width, height = pil_image.size
174
+ new_height = int(height*(new_width/width))
175
+ pil_image = pil_image.resize((new_width, new_height))
176
+ return pil_image
177
+
178
  model = ModelManager(
179
  name='lama',
180
  device=device,
 
197
  image = np.array(image_pil)
198
  mask = np.array(mask_pil.convert("L"))
199
  output = model_process(image, mask, img_enhancer)
200
+ return output, [resize_image(image_pil, new_width=400), resize_image(output, new_width=400)], gr.update(visible=True)
201
 
202
  css = '''
203
  .container {max-width: 1150px; margin: auto;padding-top: 1.5rem}
 
416
 
417
  begin_button.click(fn=None, inputs=[], outputs=[group_1, group_2], _js=start_cleaner)
418
 
419
+ image_blocks.launch(server_name='0.0.0.0')