Spaces:
Runtime error
Runtime error
import tensorflow as tf | |
import math | |
import numpy as np | |
from PIL import Image | |
from tensorflow.keras.preprocessing.image import img_to_array | |
from huggingface_hub import from_pretrained_keras | |
import gradio as gr | |
model = from_pretrained_keras("keras-io/super-resolution") | |
def infer(image): | |
img = Image.fromarray(image) | |
img = img.resize((100,100)) | |
ycbcr = img.convert("YCbCr") | |
y, cb, cr = ycbcr.split() | |
y = img_to_array(y) | |
y = y.astype("float32") / 255.0 | |
input = np.expand_dims(y, axis=0) | |
out = model.predict(input) | |
out_img_y = out[0] | |
out_img_y *= 255.0 | |
# Restore the image in RGB color space. | |
out_img_y = out_img_y.clip(0, 255) | |
out_img_y = out_img_y.reshape((np.shape(out_img_y)[0], np.shape(out_img_y)[1])) | |
out_img_y = Image.fromarray(np.uint8(out_img_y), mode="L") | |
out_img_cb = cb.resize(out_img_y.size, Image.BICUBIC) | |
out_img_cr = cr.resize(out_img_y.size, Image.BICUBIC) | |
out_img = Image.merge("YCbCr", (out_img_y, out_img_cb, out_img_cr)).convert( | |
"RGB" | |
) | |
return (img,out_img) | |
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>" | |
iface = gr.Interface( | |
fn=infer, | |
title = " Image Super-resolution", | |
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' 👀", | |
article = article, | |
inputs=gr.inputs.Image(type="numpy",label="Input Image"), | |
outputs=[gr.outputs.Image(type="numpy",label="Resized 100x100 image"), | |
gr.outputs.Image(type="numpy",label="Super-resolution 300x300 image") | |
], | |
examples=[["camel.jpg"], ["pokemon.jpg"]], | |
).launch() |