import tensorflow as tf import numpy as np from PIL import Image from glob import glob import pandas as pd 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") model.summary() def infer(image): nx=image.shape[0] ny=image.shape[1] img = Image.fromarray(image) # img = img.resize((100,100)) # img = img.crop((0,100,0,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) nxo = out.squeeze().shape[0] nyo = out.squeeze().shape[1] 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" ) out_img.save('output.png') out = {} out.update( {'input image size x': nx } ) out.update( {'output image size x': nxo } ) out.update( {'input image size y': ny } ) out.update( {'output image size y': nyo } ) return (pd.DataFrame(data=out.values(), index=out.keys()).transpose(), img,out_img, 'output.png') article = "