Spaces:
Runtime error
Runtime error
File size: 2,190 Bytes
d1dfe2f fbc62a1 9320c3b bf2220c 9320c3b af462dd 9320c3b d1dfe2f b3c88ac bf2220c b3c88ac 2149ece 95845a7 75e49a0 b3c88ac 75e49a0 0fc7951 74ecf72 95845a7 af462dd 9dcbc92 28d254a 74ecf72 af462dd 74ecf72 9dcbc92 b3c88ac 9320c3b b3c88ac d1dfe2f 2f3dd60 3ec167a d1dfe2f af462dd 2721e7b d1dfe2f |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 |
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() |