|
import gradio as gr |
|
from tensorflow.keras.models import load_model |
|
import numpy as np |
|
from PIL import Image |
|
from keras.preprocessing import image |
|
|
|
def preprocess_image(image_path, target_size=(500, 500)): |
|
img = Image.open(image_path).convert('L') |
|
img_array = image.img_to_array(img) |
|
img_array = np.expand_dims(img_array, axis=0) |
|
img_array = img_array.astype('float32') / 255.0 |
|
return img_array |
|
|
|
def denoise_image(image_path): |
|
|
|
model = load_model('model.h5') |
|
|
|
|
|
img_array = preprocess_image(image_path) |
|
|
|
|
|
denoised_img = model.predict(img_array) |
|
denoised_img = np.squeeze(denoised_img) |
|
|
|
|
|
denoised_img = (denoised_img * 255).astype(np.uint8) |
|
denoised_img_pil = Image.fromarray(denoised_img) |
|
|
|
return denoised_img_pil |
|
|
|
image_interface = gr.Interface( |
|
fn=denoise_image, |
|
inputs=gr.Image(sources=['upload'], type='filepath', label='Upload Image'), |
|
outputs=gr.Image(label='Denoised Image', type='pil', height=500, width=500), |
|
title='Image Denoiser', |
|
description='Upload an image to denoise.', |
|
allow_flagging=False |
|
) |
|
|
|
image_interface.launch() |
|
|
|
|