Najaf-Zawar commited on
Commit
86c46ff
1 Parent(s): 92d8c83

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +34 -0
app.py ADDED
@@ -0,0 +1,34 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import cv2
2
+ import os
3
+ import torch
4
+ from basicsr.archs.rrdbnet_arch import RRDBNet
5
+ from realesrgan import RealESRGANer
6
+
7
+ import gradio as gr
8
+ import torchvision.transforms as transforms
9
+
10
+
11
+ model_path = "Trained_ESRGAN.pth"
12
+ device = torch.device("cuda" if torch.cuda.is_available() else "cpu")
13
+ model = RRDBNet(num_in_ch=3, num_out_ch=3, num_feat=64, num_block=23, num_grow_ch=32, scale=4)
14
+ upsampler = RealESRGANer(scale=4, model_path=model_path, model=model)
15
+
16
+
17
+
18
+ def esrgan(input_image):
19
+ output_img, _ = upsampler.enhance(input_image, outscale=3.5)
20
+ filename = "output.jpg"
21
+ output_img = cv2.cvtColor(output_img, cv2.COLOR_BGR2RGB)
22
+ cv2.imwrite(filename, output_img)
23
+ return filename
24
+
25
+
26
+ # Define the Gradio app interface
27
+ inputs = gr.Image(label="Input Image")
28
+ outputs = gr.Image(label="Enhanced_Image.")
29
+ title = "Image Super-Resolution Using ESR-GAN"
30
+ description = "Enhance the Quality of your Low Resolution Images To High Resolution Using Artificial Intelligence"
31
+
32
+ iface = gr.Interface(fn=esrgan, inputs=inputs, outputs=outputs, title=title, description=description, allow_flagging="never")
33
+
34
+ iface.launch(inline = False)