ahmedabdelwahed commited on
Commit
2f15fa5
1 Parent(s): 62b88d2

Upload app.py

Browse files
Files changed (1) hide show
  1. app.py +41 -0
app.py ADDED
@@ -0,0 +1,41 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import tensorflow as tf
2
+ from simple_unet_model import simple_unet_model
3
+ from tensorflow.keras.utils import normalize
4
+ import os
5
+ from PIL import Image, ImageOps
6
+ import numpy as np
7
+ import gradio as gr
8
+
9
+ #Loading Model
10
+ def get_model():
11
+ return simple_unet_model(256, 256, 1)
12
+
13
+ model = get_model()
14
+ model.load_weights('mitochondria.hdf5')
15
+
16
+ def predict(input_image):
17
+ img = Image.fromarray(input_image)
18
+ gray_img = ImageOps.grayscale(img)
19
+ resized_img = gray_img.resize((256,256))
20
+ img = np.array(resized_img)
21
+ img = np.expand_dims(img, axis = (0,3))
22
+ img = normalize(img, axis=1)
23
+ mask = model.predict(img)[0,:,:,0]
24
+ return mask
25
+
26
+ def load_examples():
27
+ files = os.listdir('examples/')
28
+ img_list = []
29
+ for file in files:
30
+ if '.jpg' in file:
31
+ img_list.append(str('examples/' + file))
32
+ return img_list
33
+
34
+ examples = load_examples()
35
+
36
+ demo = gr.Interface(fn=predict,
37
+ inputs="image",
38
+ outputs=gr.Image(shape=(256, 256)),
39
+ title = "Mitochondria Detection",
40
+ examples =examples )
41
+ demo.launch()