Dvjc1899 commited on
Commit
a1fac21
·
1 Parent(s): 9b4a05a

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +30 -6
app.py CHANGED
@@ -1,17 +1,41 @@
1
  import tensorflow as tf
 
 
 
 
2
  from huggingface_hub import from_pretrained_keras
3
  import gradio as gr
4
 
5
  model = from_pretrained_keras("Dvjc1899/super-resolution")
6
 
7
- def infer():
8
- return("hello world")
9
-
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
10
  iface = gr.Interface(
11
  fn=infer,
12
  title = "Super-resolution",
13
- inputs=["text"],
14
- outputs=[
15
- "textbox",
16
  ],
17
  ).launch()
 
1
  import tensorflow as tf
2
+
3
+ import math
4
+ import numpy as np
5
+
6
  from huggingface_hub import from_pretrained_keras
7
  import gradio as gr
8
 
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,
37
  title = "Super-resolution",
38
+ inputs=gr.inputs.Image(label="Input Image"),
39
+ outputs=[gr.outputs.Image(label="Super-resolution image"),
 
40
  ],
41
  ).launch()