Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
@@ -9,28 +9,28 @@ import gradio as gr
|
|
9 |
model = from_pretrained_keras("Dvjc1899/super-resolution")
|
10 |
|
11 |
def infer(img):
|
12 |
-
|
13 |
ycbcr = img.convert("YCbCr")
|
14 |
-
|
15 |
-
|
16 |
-
|
17 |
|
18 |
-
|
19 |
-
|
20 |
|
21 |
-
|
22 |
-
|
23 |
|
24 |
-
|
25 |
-
|
26 |
-
|
27 |
-
|
28 |
-
|
29 |
-
|
30 |
-
|
31 |
-
|
32 |
-
|
33 |
-
|
34 |
|
35 |
iface = gr.Interface(
|
36 |
fn=infer,
|
|
|
9 |
model = from_pretrained_keras("Dvjc1899/super-resolution")
|
10 |
|
11 |
def infer(img):
|
12 |
+
img = img.resize((300, 300))
|
13 |
ycbcr = img.convert("YCbCr")
|
14 |
+
y, cb, cr = ycbcr.split()
|
15 |
+
y = img_to_array(y)
|
16 |
+
y = y.astype("float32") / 255.0
|
17 |
|
18 |
+
input = np.expand_dims(y, axis=0)
|
19 |
+
out = model.predict(input)
|
20 |
|
21 |
+
out_img_y = out[0]
|
22 |
+
out_img_y *= 255.0
|
23 |
|
24 |
+
# Restore the image in RGB color space.
|
25 |
+
out_img_y = out_img_y.clip(0, 255)
|
26 |
+
out_img_y = out_img_y.reshape((np.shape(out_img_y)[0], np.shape(out_img_y)[1]))
|
27 |
+
out_img_y = PIL.Image.fromarray(np.uint8(out_img_y), mode="L")
|
28 |
+
out_img_cb = cb.resize(out_img_y.size, PIL.Image.BICUBIC)
|
29 |
+
out_img_cr = cr.resize(out_img_y.size, PIL.Image.BICUBIC)
|
30 |
+
out_img = PIL.Image.merge("YCbCr", (out_img_y, out_img_cb, out_img_cr)).convert(
|
31 |
+
"RGB"
|
32 |
+
)
|
33 |
+
return out_img
|
34 |
|
35 |
iface = gr.Interface(
|
36 |
fn=infer,
|