Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
|
@@ -5,9 +5,8 @@ import tensorflow as tf
|
|
| 5 |
from tensorflow import keras
|
| 6 |
from huggingface_hub import from_pretrained_keras
|
| 7 |
|
| 8 |
-
|
| 9 |
model = from_pretrained_keras("keras-io/low-light-image-enhancement", compile=False)
|
| 10 |
-
examples = ['got2.png', 'gotj.png', 'goti.png'
|
| 11 |
|
| 12 |
def get_enhanced_image(data, output):
|
| 13 |
r1 = output[:, :, :, :3]
|
|
@@ -27,25 +26,22 @@ def get_enhanced_image(data, output):
|
|
| 27 |
x = x + r7 * (tf.square(x) - x)
|
| 28 |
enhanced_image = x + r8 * (tf.square(x) - x)
|
| 29 |
return enhanced_image
|
| 30 |
-
|
| 31 |
-
|
| 32 |
def infer(original_image):
|
| 33 |
image = keras.preprocessing.image.img_to_array(original_image)
|
| 34 |
image = image.astype("float32") / 255.0
|
| 35 |
image = np.expand_dims(image, axis=0)
|
| 36 |
output = model.predict(image)
|
| 37 |
output = get_enhanced_image(image, output)
|
| 38 |
-
output_image = tf.cast(
|
| 39 |
-
|
| 40 |
-
return output_image
|
| 41 |
-
|
| 42 |
|
| 43 |
iface = gr.Interface(
|
| 44 |
fn=infer,
|
| 45 |
-
title="Zero-DCE for
|
| 46 |
-
description
|
| 47 |
-
inputs=
|
| 48 |
-
outputs=
|
| 49 |
examples=examples,
|
| 50 |
-
article
|
| 51 |
-
|
|
|
|
| 5 |
from tensorflow import keras
|
| 6 |
from huggingface_hub import from_pretrained_keras
|
| 7 |
|
|
|
|
| 8 |
model = from_pretrained_keras("keras-io/low-light-image-enhancement", compile=False)
|
| 9 |
+
examples = ['got2.png', 'gotj.png', 'goti.png']
|
| 10 |
|
| 11 |
def get_enhanced_image(data, output):
|
| 12 |
r1 = output[:, :, :, :3]
|
|
|
|
| 26 |
x = x + r7 * (tf.square(x) - x)
|
| 27 |
enhanced_image = x + r8 * (tf.square(x) - x)
|
| 28 |
return enhanced_image
|
| 29 |
+
|
|
|
|
| 30 |
def infer(original_image):
|
| 31 |
image = keras.preprocessing.image.img_to_array(original_image)
|
| 32 |
image = image.astype("float32") / 255.0
|
| 33 |
image = np.expand_dims(image, axis=0)
|
| 34 |
output = model.predict(image)
|
| 35 |
output = get_enhanced_image(image, output)
|
| 36 |
+
output_image = tf.cast(output[0, :, :, :] * 255, dtype=tf.uint8).numpy()
|
| 37 |
+
return Image.fromarray(output_image)
|
|
|
|
|
|
|
| 38 |
|
| 39 |
iface = gr.Interface(
|
| 40 |
fn=infer,
|
| 41 |
+
title="Zero-DCE for Low-Light Image Enhancement",
|
| 42 |
+
description="Implementing Zero-Reference Deep Curve Estimation for low-light image enhancement.",
|
| 43 |
+
inputs=gr.Image(label="Original Image", type="pil"),
|
| 44 |
+
outputs=gr.Image(label="Enhanced Image"),
|
| 45 |
examples=examples,
|
| 46 |
+
article="**Original Author**: [Soumik Rakshit](https://github.com/soumik12345) <br>**HF Contribution**: [Harveen Singh Chadha](https://github.com/harveenchadha)<br>",
|
| 47 |
+
).launch(debug=True, enable_queue=False, cache_examples=True)
|