myimageupscaler / app.py
Kev09's picture
Update app.py
d9dba4b
raw
history blame
1.9 kB
import gradio as gr
import numpy as np
import torch
from super_image import EdsrModel, ImageLoader
from PIL import Image
import requests
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'
image = Image.open(requests.get(url, stream=True).raw)
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()
print('pnump',type(prednumpy))
print('predtype',type(preds))
print('ok3')
prednumpy = np.squeeze(prednumpy)
return prednumpy
# 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='numpy')
button.click(fn=transformation,inputs=image1,outputs=image2,api_name="upscale")
iface = gr.Interface(fn=greet, inputs="text", outputs="text")
demo.launch()