Spaces:
Runtime error
Runtime error
Commit ·
2277923
1
Parent(s): 8f65403
Update model.py
Browse files
model.py
CHANGED
|
@@ -1,16 +1,26 @@
|
|
| 1 |
import numpy as np
|
| 2 |
import gradio as gr
|
| 3 |
from PIL import Image
|
|
|
|
| 4 |
import keras
|
| 5 |
from huggingface_hub import from_pretrained_keras
|
| 6 |
|
| 7 |
|
| 8 |
-
model = from_pretrained_keras("
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
def infer(original_image):
|
| 13 |
image = keras.utils.img_to_array(original_image)
|
|
|
|
| 14 |
image = image.astype("float32") / 255.0
|
| 15 |
image = np.expand_dims(image, axis=0)
|
| 16 |
output = model.predict(image)
|
|
|
|
| 1 |
import numpy as np
|
| 2 |
import gradio as gr
|
| 3 |
from PIL import Image
|
| 4 |
+
import tensorflow as tf
|
| 5 |
import keras
|
| 6 |
from huggingface_hub import from_pretrained_keras
|
| 7 |
|
| 8 |
|
| 9 |
+
model = from_pretrained_keras("hbpkillerX/image_enhancer", compile=False)
|
| 10 |
+
|
| 11 |
+
def autocontrast(tensor, cutoff=0):
|
| 12 |
+
tensor = tf.cast(tensor, dtype=tf.float32)
|
| 13 |
+
min_val = tf.reduce_min(tensor)
|
| 14 |
+
max_val = tf.reduce_max(tensor)
|
| 15 |
+
range_val = max_val - min_val
|
| 16 |
+
adjusted_tensor = tf.clip_by_value(tf.cast(tf.round((tensor - min_val - cutoff) * (255 / (range_val - 2 * cutoff))), tf.uint8), 0, 255)
|
| 17 |
+
return adjusted_tensor
|
| 18 |
|
| 19 |
|
| 20 |
|
| 21 |
def infer(original_image):
|
| 22 |
image = keras.utils.img_to_array(original_image)
|
| 23 |
+
image = autocontrast(image)
|
| 24 |
image = image.astype("float32") / 255.0
|
| 25 |
image = np.expand_dims(image, axis=0)
|
| 26 |
output = model.predict(image)
|