Add application file
Browse files- app.py +41 -0
- model.h5 +3 -0
- requirements.txt +0 -0
app.py
ADDED
@@ -0,0 +1,41 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import gradio as gr
|
2 |
+
from tensorflow.keras.models import load_model
|
3 |
+
import numpy as np
|
4 |
+
from PIL import Image
|
5 |
+
from keras.preprocessing import image
|
6 |
+
|
7 |
+
def preprocess_image(image_path, target_size=(500, 500)):
|
8 |
+
img = Image.open(image_path).convert('L') # Convert to grayscale
|
9 |
+
img_array = image.img_to_array(img)
|
10 |
+
img_array = np.expand_dims(img_array, axis=0)
|
11 |
+
img_array = img_array.astype('float32') / 255.0 # Normalize pixel values between 0 and 1
|
12 |
+
return img_array
|
13 |
+
|
14 |
+
def denoise_image(image_path):
|
15 |
+
# Load the denoising autoencoder model
|
16 |
+
model = load_model('model.h5')
|
17 |
+
|
18 |
+
# Preprocess the image
|
19 |
+
img_array = preprocess_image(image_path)
|
20 |
+
|
21 |
+
# Denoise the image using the autoencoder model
|
22 |
+
denoised_img = model.predict(img_array)
|
23 |
+
denoised_img = np.squeeze(denoised_img) # Remove batch dimension
|
24 |
+
|
25 |
+
# Convert the denoised image array to PIL Image
|
26 |
+
denoised_img = (denoised_img * 255).astype(np.uint8)
|
27 |
+
denoised_img_pil = Image.fromarray(denoised_img)
|
28 |
+
|
29 |
+
return denoised_img_pil
|
30 |
+
|
31 |
+
image_interface = gr.Interface(
|
32 |
+
fn=denoise_image,
|
33 |
+
inputs=gr.Image(sources=['upload'], type='filepath', label='Upload Image'),
|
34 |
+
outputs=gr.Image(label='Denoised Image', type='pil', height=500, width=500),
|
35 |
+
title='Image Denoiser',
|
36 |
+
description='Upload an image to denoise.',
|
37 |
+
allow_flagging=False
|
38 |
+
)
|
39 |
+
|
40 |
+
image_interface.launch()
|
41 |
+
|
model.h5
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:d0ffb13b3eb1fb8829d0b9ddbdfd6d8adcbdefeed7f6863a5c4100d1def07748
|
3 |
+
size 4142984
|
requirements.txt
ADDED
Binary file (84 Bytes). View file
|
|