Spaces:
Runtime error
Runtime error
fix memory limit exceeded, resize image shape
Browse files- app.py +14 -2
- test-img.jpg +0 -0
app.py
CHANGED
@@ -3,9 +3,17 @@ 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")
|
@@ -36,7 +44,7 @@ if __name__ == '__main__':
|
|
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"
|
@@ -45,5 +53,9 @@ if __name__ == '__main__':
|
|
45 |
outputs=outputs,
|
46 |
allow_screenshot=False,
|
47 |
allow_flagging='never',
|
48 |
-
|
|
|
|
|
|
|
|
|
49 |
iface.launch()
|
|
|
3 |
import time
|
4 |
import logging
|
5 |
import os
|
6 |
+
from PIL import ImageOps
|
7 |
+
import numpy as np
|
8 |
+
import math
|
9 |
|
10 |
|
11 |
def greet(input_img, input_model_name, input_tile_mode):
|
12 |
+
if input_img.size[0] * input_img.size[1] > 256 * 256:
|
13 |
+
y = int(math.sqrt(256*256/input_img.size[0]*input_img.size[1]))
|
14 |
+
x = int(input_img.size[0]/input_img.size[1]*y)
|
15 |
+
input_img = ImageOps.fit(input_img, (x, y))
|
16 |
+
input_img = np.array(input_img)
|
17 |
if input_model_name not in model_cache:
|
18 |
t1 = time.time()
|
19 |
upscaler = RealWaifuUpScaler(input_model_name[2], ModelPath + input_model_name, half=False, device="cpu")
|
|
|
44 |
|
45 |
input_model_name = gr.inputs.Dropdown(os.listdir(ModelPath), default="up2x-latest-no-denoise.pth", label='选择model')
|
46 |
input_tile_mode = gr.inputs.Dropdown([0, 1, 2, 3, 4], default=2, label='选择tile_mode')
|
47 |
+
input_img = gr.inputs.Image(label='image', type='pil')
|
48 |
|
49 |
inputs = [input_img, input_model_name, input_tile_mode]
|
50 |
outputs = "image"
|
|
|
53 |
outputs=outputs,
|
54 |
allow_screenshot=False,
|
55 |
allow_flagging='never',
|
56 |
+
examples=[['test-img.jpg', "up2x-latest-no-denoise.pth", 2]],
|
57 |
+
article='[https://github.com/bilibili/ailab/tree/main/Real-CUGAN](https://github.com/bilibili/ailab/tree/main/Real-CUGAN)<br>'
|
58 |
+
'感谢b站开源的项目,图片过大会导致内存不足,所有我将图片裁剪小,想体验大图片的效果请自行前往上面的链接。<br>'
|
59 |
+
'The large image will lead to memory limit exceeded. So I crop and resize image. '
|
60 |
+
'If you want to experience the large image, please go to the link above.')
|
61 |
iface.launch()
|
test-img.jpg
ADDED