Ekins Kuuzie commited on
Commit
37d8430
·
verified ·
1 Parent(s): 766ef11

initial commit

Browse files
Files changed (1) hide show
  1. app.py +40 -0
app.py ADDED
@@ -0,0 +1,40 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ##importing the libraries
2
+ import numpy as np
3
+ import pandas as pd
4
+ from PIL import Image
5
+ import cv2
6
+ import tensorflow as tf
7
+ import os
8
+ import matplotlib.pyplot as plt
9
+ %matplotlib inline
10
+ from tensorflow.keras.models import load_model
11
+ import gradio as gr
12
+
13
+
14
+ # Load your trained model
15
+ model = load_model('tb_pretrained.h5')
16
+
17
+ ### Preprocess the new image
18
+
19
+ def predict_image(test_image):
20
+ # img = cv2.imread(test_image)
21
+ img = np.array(test_image)
22
+
23
+ image_1 = tf.image.resize(img, (256,256))
24
+
25
+ image_processed = np.expand_dims(image_1/256, 0)
26
+
27
+ ##prediction
28
+
29
+ yhat = model.predict(image_processed)
30
+
31
+ ## setting a threshold
32
+ if yhat[0][1] > 0.70:
33
+ return (f'There is {round((yhat[0][1])*100,2)}% chance of the image being normal')
34
+ elif yhat[0][0] > 0.9:
35
+ return (f'There is {round((yhat[0][0])*100,2)}% chance of an abnormality either than TB being present')
36
+ else:
37
+ return (f'There is a chance of TB being present')
38
+
39
+
40
+ gr.Interface(predict_image, "image", "label").launch(debug=True, share=True)