abbylagar commited on
Commit
69f3645
1 Parent(s): 95f7660

Upload app.py

Browse files
Files changed (1) hide show
  1. app.py +50 -0
app.py ADDED
@@ -0,0 +1,50 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ """
2
+ hugging face app.py file
3
+ """
4
+
5
+
6
+ #import functions
7
+
8
+ import matplotlib.pylab as plt
9
+ import PIL.Image as Image
10
+ import gradio as gr
11
+ import torch
12
+ import torchvision
13
+ from torch import nn
14
+ from einops import rearrange, reduce
15
+ from pytorch_lightning import LightningModule, Trainer, Callback
16
+ from pytorch_lightning.loggers import WandbLogger
17
+ from torch.optim import Adam
18
+ from torch.optim.lr_scheduler import CosineAnnealingLR
19
+ from denoiseCIFAR100 import DenoiseCIFAR100Model
20
+ from torchvision import transforms
21
+ from PIL import Image
22
+ import numpy as np
23
+
24
+
25
+
26
+ modelcheck = DenoiseCIFAR100Model.load_from_checkpoint("./autoencoder_model.ckpt")
27
+ modelcheck=modelcheck.eval()
28
+
29
+ def denoise(image):
30
+ in_im=tinp = transforms.ToTensor()(image).unsqueeze(0)
31
+ with torch.no_grad():
32
+ out_im = modelcheck(in_im)
33
+
34
+ out = out_im[0].permute(1, 2, 0)
35
+ out = out.numpy()
36
+ im = Image.fromarray((out * 255).astype(np.uint8))
37
+ im.save("./output.jpeg")
38
+ return "./output.jpeg"
39
+
40
+
41
+
42
+ iface = gr.Interface(denoise, inputs=gr.inputs.Image(shape=(32,32), image_mode="RGB", type="numpy",label="Input"),
43
+ outputs=gr.outputs.Image(type="file",label="Output"),
44
+ examples=["panda.jpeg","outside.jpeg"],
45
+ live=False,layout="horizontal", interpretation=None,
46
+ title="CIFAR100 Denoising",
47
+ #description=description,
48
+ #article=article
49
+ )
50
+ iface.launch()