Spaces:
Runtime error
Runtime error
harveen
commited on
Commit
Β·
1b6ea60
1
Parent(s):
7b6e016
Adding app.pyy
Browse files
app.py
CHANGED
|
@@ -0,0 +1,44 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import numpy as np
|
| 2 |
+
import gradio as gr
|
| 3 |
+
from PIL import Image
|
| 4 |
+
import tensorflow as tf
|
| 5 |
+
from tensorflow import keras
|
| 6 |
+
from huggingface_hub import from_pretrained_keras
|
| 7 |
+
|
| 8 |
+
|
| 9 |
+
model = from_pretrained_keras("Harveenchadha/low-light-image-enhancement", compile=False)
|
| 10 |
+
#examples = ['examples/179.png', 'examples/493.png', 'examples/780.png']
|
| 11 |
+
|
| 12 |
+
|
| 13 |
+
def infer(original_image):
|
| 14 |
+
image = keras.preprocessing.image.img_to_array(original_image)
|
| 15 |
+
image = image.astype("float32") / 255.0
|
| 16 |
+
image = np.expand_dims(image, axis=0)
|
| 17 |
+
output = model.predict(image)
|
| 18 |
+
# print(len(output))
|
| 19 |
+
# print([len(a) for a in output])
|
| 20 |
+
output_image = output[0] * 255.0
|
| 21 |
+
output_image = output_image.clip(0, 255)
|
| 22 |
+
output_image = output_image.reshape(
|
| 23 |
+
(np.shape(output_image)[0], np.shape(output_image)[1], 3)
|
| 24 |
+
)
|
| 25 |
+
output_image = np.uint32(output_image)
|
| 26 |
+
|
| 27 |
+
# output_image = tf.cast((output[0, :, :, :] * 255), dtype=np.uint8)
|
| 28 |
+
|
| 29 |
+
|
| 30 |
+
# #output_image = Image.fromarray(output_image.numpy())
|
| 31 |
+
# output_image = output_image.numpy()
|
| 32 |
+
# print(output_image.shape())
|
| 33 |
+
return output_image
|
| 34 |
+
|
| 35 |
+
|
| 36 |
+
iface = gr.Interface(
|
| 37 |
+
fn=infer,
|
| 38 |
+
title="Low Light Image Enhancement",
|
| 39 |
+
description = "Keras Implementation of MIRNet model for light up the dark image ππ",
|
| 40 |
+
inputs=[gr.inputs.Image(label="image", type="pil")],
|
| 41 |
+
outputs=[gr.outputs.Image(label="image", type="numpy")],
|
| 42 |
+
#examples=examples,
|
| 43 |
+
article = "Author: <a href=\"https://huggingface.co/vumichien\">Vu Minh Chien</a>. Based on the keras example from <a href=\"https://keras.io/examples/vision/mirnet/\">Soumik Rakshit</a>",
|
| 44 |
+
).launch(debug=True)
|