tykimos commited on
Commit
9938794
·
1 Parent(s): 1ce3628

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +47 -4
app.py CHANGED
@@ -1,7 +1,50 @@
 
 
 
 
 
 
 
 
1
  import gradio as gr
2
 
3
- def greet(name):
4
- return "Hello " + name + "!!"
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
5
 
6
- iface = gr.Interface(fn=greet, inputs="text", outputs="text")
7
- iface.launch()
 
 
 
 
 
 
 
 
 
 
1
+ import tensorflow as tf
2
+
3
+ import math
4
+ import numpy as np
5
+ from PIL import Image
6
+
7
+ from tensorflow.keras.preprocessing.image import img_to_array
8
+ from huggingface_hub import from_pretrained_keras
9
  import gradio as gr
10
 
11
+ model = from_pretrained_keras("keras-io/super-resolution")
12
+
13
+ def infer(image):
14
+ img = Image.fromarray(image)
15
+ img = img.resize((100,100))
16
+ ycbcr = img.convert("YCbCr")
17
+ y, cb, cr = ycbcr.split()
18
+ y = img_to_array(y)
19
+ y = y.astype("float32") / 255.0
20
+
21
+ input = np.expand_dims(y, axis=0)
22
+ out = model.predict(input)
23
+
24
+ out_img_y = out[0]
25
+ out_img_y *= 255.0
26
+
27
+ # Restore the image in RGB color space.
28
+ out_img_y = out_img_y.clip(0, 255)
29
+ out_img_y = out_img_y.reshape((np.shape(out_img_y)[0], np.shape(out_img_y)[1]))
30
+ out_img_y = Image.fromarray(np.uint8(out_img_y), mode="L")
31
+ out_img_cb = cb.resize(out_img_y.size, Image.BICUBIC)
32
+ out_img_cr = cr.resize(out_img_y.size, Image.BICUBIC)
33
+ out_img = Image.merge("YCbCr", (out_img_y, out_img_cb, out_img_cr)).convert(
34
+ "RGB"
35
+ )
36
+ return (img,out_img)
37
+
38
+ article = "<p style='text-align: center'><a href='https://arxiv.org/abs/1609.05158' target='_blank'>Real-Time Single Image and Video Super-Resolution Using an Efficient Sub-Pixel Convolutional Neural Network</a></p><center> <a href='https://keras.io/examples/vision/super_resolution_sub_pixel/' target='_blank'>Image Super-Resolution using an Efficient Sub-Pixel CNN</a></p> <center>Contributors: <a href='https://twitter.com/Cr0wley_zz'>Devjyoti Chakraborty</a>|<a href='https://twitter.com/ritwik_raha'>Ritwik Raha</a>|<a href='https://twitter.com/ariG23498'>Aritra Roy Gosthipaty</a></center>"
39
 
40
+ iface = gr.Interface(
41
+ fn=infer,
42
+ title = " Image Super-resolution",
43
+ description = "This space is a demo of the keras tutorial 'Image Super-Resolution using an Efficient Sub-Pixel CNN' based on the paper 'Real-Time Single Image and Video Super-Resolution Using an Efficient Sub-Pixel Convolutional Neural Network' 👀",
44
+ article = article,
45
+ inputs=gr.inputs.Image(label="Input Image"),
46
+ outputs=[gr.outputs.Image(label="Resized 100x100 image"),
47
+ gr.outputs.Image(label="Super-resolution 300x300 image")
48
+ ],
49
+ examples=[["camel.jpg"], ["pokemon.jpg"]],
50
+ ).launch()