vumichien commited on
Commit
27f758a
1 Parent(s): 03ab858

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +6 -2
app.py CHANGED
@@ -1,5 +1,7 @@
1
  import numpy as np
2
  import gradio as gr
 
 
3
  from huggingface_hub import from_pretrained_keras
4
 
5
 
@@ -7,7 +9,9 @@ model = from_pretrained_keras("keras-io/lowlight-enhance-mirnet", compile=False)
7
  examples = ['examples/179.png', 'examples/493.png', 'examples/780.png']
8
 
9
 
10
- def infer(image):
 
 
11
  image = np.expand_dims(image, axis=0)
12
  output = model.predict(image)
13
  output_image = output[0] * 255.0
@@ -15,9 +19,9 @@ def infer(image):
15
  output_image = output_image.reshape(
16
  (np.shape(output_image)[0], np.shape(output_image)[1], 3)
17
  )
 
18
  return output_image
19
 
20
-
21
  iface = gr.Interface(
22
  fn=infer,
23
  inputs=[gr.inputs.Image(label="image", type="pil", shape=(128, 128))],
 
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
 
 
9
  examples = ['examples/179.png', 'examples/493.png', 'examples/780.png']
10
 
11
 
12
+ def infer(original_image):
13
+ image = keras.preprocessing.image.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)
17
  output_image = output[0] * 255.0
 
19
  output_image = output_image.reshape(
20
  (np.shape(output_image)[0], np.shape(output_image)[1], 3)
21
  )
22
+ output_image = Image.fromarray(np.uint8(output_image))
23
  return output_image
24
 
 
25
  iface = gr.Interface(
26
  fn=infer,
27
  inputs=[gr.inputs.Image(label="image", type="pil", shape=(128, 128))],