import gradio as gr import numpy as np import torch from super_image import EdsrModel, ImageLoader from PIL import Image import requests import torchvision import torchvision.transforms as T def greet(name): return "Hello " + name + "!!" def transformation(image): # print(image) # print( type(image) ) # url = 'https://paperswithcode.com/media/datasets/Set5-0000002728-07a9793f_zA3bDjj.jpg' # imagee = Image.open(requests.get(url, stream=True).raw) # model = EdsrModel.from_pretrained('eugenesiow/edsr-base', scale=4) # inputs = ImageLoader.load_image(imagee) # preds = model(inputs) # print("1 :",preds) # print( type(preds) ) # prednumpy=preds.detach().numpy() #preds=np.array(preds) # print("2 :",prednumpy) # ImageLoader.save_image(preds, './scaled_2x.png') # ImageLoader.save_compare(inputs, preds, './scaled_2x_compare.png') url = 'https://paperswithcode.com/media/datasets/Set5-0000002728-07a9793f_zA3bDjj.jpg' url='photofloue.jpg' # image = Image.open(requests.get(url, stream=True).raw) image = Image.open(url) model = EdsrModel.from_pretrained('eugenesiow/edsr-base', scale=4) print('ok') inputs = ImageLoader.load_image(image) preds = model(inputs) print('ok1') # ImageLoader.save_image(preds, './scaled_2x.png') ImageLoader.save_compare(inputs, preds, 'scaleed_2x_compare.png') print("ok2") #prednumpy=preds.detach().numpy() preds = preds.data.cpu().numpy() pred = preds[0].transpose((1, 2, 0)) * 255.0 # return Image.fromarray(pred.astype('uint8'), 'RGB') # print('pnump',type(prednumpy)) print('predtype',type(preds)) print('ok3') # prednumpy = np.squeeze(prednumpy) return Image.fromarray(pred.astype('uint8'), 'RGB') # large_image = cartoon_upsampling_8x(image, 'a_8x_larger_output_image.png' ) # return prednumpy with gr.Blocks() as demo: image1=gr.Image(type='filepath') button=gr.Button("LE BOUTON") image2=gr.Image(type='pil') button.click(fn=transformation,inputs=image1,outputs=image2,api_name="upscale") iface = gr.Interface(fn=greet, inputs="text", outputs="text") demo.launch()