Spaces:
Runtime error
Runtime error
Commit
·
28c76d4
1
Parent(s):
89decbb
Create app.py
Browse files
app.py
ADDED
@@ -0,0 +1,34 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import cv2
|
2 |
+
import numpy
|
3 |
+
import os
|
4 |
+
import torch
|
5 |
+
import random
|
6 |
+
from basicsr.archs.rrdbnet_arch import RRDBNet
|
7 |
+
from realesrgan import RealESRGANer
|
8 |
+
|
9 |
+
import gradio as gr
|
10 |
+
from skimage.restoration import inpaint as p
|
11 |
+
import torchvision.transforms as transforms
|
12 |
+
|
13 |
+
|
14 |
+
def restore_image(input_image):
|
15 |
+
img = cv2.cvtColor(input_image, cv2.COLOR_BGR2GRAY)
|
16 |
+
threshold_value = 200
|
17 |
+
_, mask = cv2.threshold(img, threshold_value, 255, cv2.THRESH_BINARY)
|
18 |
+
channels = cv2.split(img)
|
19 |
+
inpaint_channels = []
|
20 |
+
for channel in channels:
|
21 |
+
inpaint_result = p.inpaint_biharmonic(channel, mask)
|
22 |
+
inpaint_channels.append(inpaint_result)
|
23 |
+
|
24 |
+
result_img = cv2.merge(inpaint_channels)
|
25 |
+
filename = "output.jpg"
|
26 |
+
cv2.imwrite(filename, result_img)
|
27 |
+
return filename
|
28 |
+
|
29 |
+
|
30 |
+
# Define the Gradio app interface
|
31 |
+
inputs = gr.Image(label="Upload Image")
|
32 |
+
outputs = gr.Image(label="Restored_Image.")
|
33 |
+
title = "Image Restoration Using Pix2Pix-GAN"
|
34 |
+
description = "Restore the Quality of your Old damaged Images To New Looking Images Using Artificial Intelligence"
|