Spaces:
Runtime error
Runtime error
Flask Backend Code
Browse files
app.py
ADDED
|
@@ -0,0 +1,38 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import gradio as gr
|
| 2 |
+
from huggingface_hub import from_pretrained_keras
|
| 3 |
+
import tensorflow as tf
|
| 4 |
+
import numpy as np
|
| 5 |
+
from PIL import Image
|
| 6 |
+
import io
|
| 7 |
+
|
| 8 |
+
# Load pre-trained deblurring model
|
| 9 |
+
model = from_pretrained_keras("google/maxim-s3-deblurring-reds")
|
| 10 |
+
|
| 11 |
+
def deblur_image(input_image):
|
| 12 |
+
# Preprocess the input image
|
| 13 |
+
image = np.array(input_image)
|
| 14 |
+
image = tf.convert_to_tensor(image)
|
| 15 |
+
image = tf.image.resize(image, (256, 256))
|
| 16 |
+
|
| 17 |
+
# Predict with the model
|
| 18 |
+
predictions = model.predict(tf.expand_dims(image, 0))
|
| 19 |
+
|
| 20 |
+
# Convert back to image
|
| 21 |
+
output_image = predictions[0].numpy().astype(np.uint8)
|
| 22 |
+
output_image = Image.fromarray(output_image)
|
| 23 |
+
|
| 24 |
+
# Save the result in memory as a byte array
|
| 25 |
+
byte_arr = io.BytesIO()
|
| 26 |
+
output_image.save(byte_arr, format='PNG')
|
| 27 |
+
byte_arr.seek(0)
|
| 28 |
+
|
| 29 |
+
return byte_arr
|
| 30 |
+
|
| 31 |
+
# Set up the Gradio interface
|
| 32 |
+
iface = gr.Interface(fn=deblur_image,
|
| 33 |
+
inputs=gr.inputs.Image(type="pil"),
|
| 34 |
+
outputs=gr.outputs.Image(type="file"),
|
| 35 |
+
live=True)
|
| 36 |
+
|
| 37 |
+
# Launch the Gradio interface
|
| 38 |
+
iface.launch()
|