Deblurring-App / app.py
gunateja's picture
Update app.py
6dd6101 verified
raw
history blame
1.16 kB
import gradio as gr
from huggingface_hub import from_pretrained_keras
import tensorflow as tf
import numpy as np
from PIL import Image
import io
# Load the model from Hugging Face Hub using from_pretrained_keras
model = from_pretrained_keras("google/maxim-s3-deblurring-reds")
def deblur_image(input_image):
# Preprocess the input image
image = np.array(input_image)
image = tf.convert_to_tensor(image)
image = tf.image.resize(image, (256, 256))
# Make predictions with the model
predictions = model.predict(tf.expand_dims(image, 0))
# Convert the prediction back to an image
output_image = predictions[0].numpy().astype(np.uint8)
output_image = Image.fromarray(output_image)
# Save the result in memory as a byte array
byte_arr = io.BytesIO()
output_image.save(byte_arr, format='PNG')
byte_arr.seek(0)
return byte_arr
# Set up the Gradio interface
iface = gr.Interface(fn=deblur_image,
inputs=gr.inputs.Image(type="pil"),
outputs=gr.outputs.Image(type="file"),
live=True)
# Launch the Gradio interface
iface.launch()