hbpkillerX commited on
Commit
5d14bf1
Β·
1 Parent(s): 00251a6

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +45 -0
app.py ADDED
@@ -0,0 +1,45 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import numpy as np
2
+ import streamlit as st
3
+ #import gradio as gr
4
+ from PIL import Image
5
+ import tensorflow as tf
6
+ import keras
7
+ from huggingface_hub import from_pretrained_keras
8
+ #dfvds
9
+
10
+ model = from_pretrained_keras("hbpkillerX/low_light_img_enhancer", compile=False)
11
+
12
+ #model= tf.saved_model.load("hbpkillerX/low_light_img_enhancer/")
13
+
14
+ def autocontrast(tensor, cutoff=0):
15
+ tensor = tf.cast(tensor, dtype=tf.float32)
16
+ min_val = tf.reduce_min(tensor)
17
+ max_val = tf.reduce_max(tensor)
18
+ range_val = max_val - min_val
19
+ adjusted_tensor = tf.clip_by_value(tf.cast(tf.round((tensor - min_val - cutoff) * (255 / (range_val - 2 * cutoff))), tf.uint8), 0, 255)
20
+ return adjusted_tensor
21
+
22
+
23
+
24
+ def infer(original_image):
25
+ image = keras.utils.img_to_array(original_image)
26
+ image = autocontrast(image)
27
+ image = image.astype("float32") / 255.0
28
+ image = np.expand_dims(image, axis=0)
29
+ output = model.predict(image)
30
+ output_image = output[0] * 255.0
31
+ output_image = output_image.clip(0, 255)
32
+ output_image = output_image.reshape(
33
+ (np.shape(output_image)[0], np.shape(output_image)[1], 3)
34
+ )
35
+ output_image = np.uint32(output_image)
36
+ return output_image
37
+
38
+ iface = st.Interface(
39
+ fn=infer,
40
+ title="Low Light Image Enhancement",
41
+ description = "Keras Implementation of MIRNet model for light up the dark image πŸŒ†πŸŽ†",
42
+ inputs=[gr.inputs.Image(label="image", type="pil", shape=(960, 640))],
43
+ outputs="image",
44
+ cache_examples=True,
45
+ )