saber2022 commited on
Commit
63545c2
1 Parent(s): a5ab92c

add more model choice

Browse files
Files changed (1) hide show
  1. app.py +37 -10
app.py CHANGED
@@ -1,22 +1,49 @@
1
- import cv2
2
  from upcunet_v3 import RealWaifuUpScaler
3
- import traceback
4
  import gradio as gr
 
 
 
5
 
6
 
7
- def greet(input_img):
8
- print(input_img.shape)
9
- result = upscaler(input_img, tile_mode=2)
10
- print(result.shape)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
11
  return result
12
 
13
 
14
  if __name__ == '__main__':
 
 
 
15
  ModelPath = "weights_v3/"
16
- ModelName = "up2x-latest-no-denoise.pth"
17
- upscaler = RealWaifuUpScaler(2, ModelPath + ModelName, half=False, device="cpu")
 
 
 
18
 
19
- inputs = gr.inputs.Image()
20
  outputs = "image"
21
- iface = gr.Interface(fn=greet, inputs=inputs, outputs=outputs)
 
 
 
 
 
22
  iface.launch()
 
 
1
  from upcunet_v3 import RealWaifuUpScaler
 
2
  import gradio as gr
3
+ import time
4
+ import logging
5
+ import os
6
 
7
 
8
+ def greet(input_img, input_model_name, input_tile_mode):
9
+ if input_model_name not in model_cache:
10
+ t1 = time.time()
11
+ upscaler = RealWaifuUpScaler(input_model_name[2], ModelPath + input_model_name, half=False, device="cpu")
12
+ t2 = time.time()
13
+ logger.info(f'load model time, {t2 - t1}')
14
+ model_cache[input_model_name] = upscaler
15
+ else:
16
+ upscaler = model_cache[input_model_name]
17
+ logger.info(f'load model from cache')
18
+
19
+ start = time.time()
20
+ result = upscaler(input_img, tile_mode=input_tile_mode)
21
+ end = time.time()
22
+ logger.info(f'input_model_name, {input_model_name}')
23
+ logger.info(f'input_tile_mode, {input_tile_mode}')
24
+ logger.info(f'input shape, {input_img.shape}')
25
+ logger.info(f'output shape, {result.shape}')
26
+ logger.info(f'speed time, {end - start}')
27
  return result
28
 
29
 
30
  if __name__ == '__main__':
31
+ logging.basicConfig(level=logging.INFO, format="[%(asctime)s] [%(process)d] [%(levelname)s] %(message)s")
32
+ logger = logging.getLogger()
33
+
34
  ModelPath = "weights_v3/"
35
+ model_cache = {}
36
+
37
+ input_model_name = gr.inputs.Dropdown(os.listdir(ModelPath), default="up2x-latest-no-denoise.pth", label='选择model')
38
+ input_tile_mode = gr.inputs.Dropdown([0, 1, 2, 3, 4], default=2, label='选择tile_mode')
39
+ input_img = gr.inputs.Image(label='image')
40
 
41
+ inputs = [input_img, input_model_name, input_tile_mode]
42
  outputs = "image"
43
+ iface = gr.Interface(fn=greet,
44
+ inputs=inputs,
45
+ outputs=outputs,
46
+ allow_screenshot=False,
47
+ allow_flagging='never',
48
+ description='https://github.com/bilibili/ailab/tree/main/Real-CUGAN\n感谢b站开源的项目')
49
  iface.launch()