Spaces:
Runtime error
Runtime error
File size: 1,399 Bytes
69f3645 |
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 |
"""
hugging face app.py file
"""
#import functions
import matplotlib.pylab as plt
import PIL.Image as Image
import gradio as gr
import torch
import torchvision
from torch import nn
from einops import rearrange, reduce
from pytorch_lightning import LightningModule, Trainer, Callback
from pytorch_lightning.loggers import WandbLogger
from torch.optim import Adam
from torch.optim.lr_scheduler import CosineAnnealingLR
from denoiseCIFAR100 import DenoiseCIFAR100Model
from torchvision import transforms
from PIL import Image
import numpy as np
modelcheck = DenoiseCIFAR100Model.load_from_checkpoint("./autoencoder_model.ckpt")
modelcheck=modelcheck.eval()
def denoise(image):
in_im=tinp = transforms.ToTensor()(image).unsqueeze(0)
with torch.no_grad():
out_im = modelcheck(in_im)
out = out_im[0].permute(1, 2, 0)
out = out.numpy()
im = Image.fromarray((out * 255).astype(np.uint8))
im.save("./output.jpeg")
return "./output.jpeg"
iface = gr.Interface(denoise, inputs=gr.inputs.Image(shape=(32,32), image_mode="RGB", type="numpy",label="Input"),
outputs=gr.outputs.Image(type="file",label="Output"),
examples=["panda.jpeg","outside.jpeg"],
live=False,layout="horizontal", interpretation=None,
title="CIFAR100 Denoising",
#description=description,
#article=article
)
iface.launch() |