File size: 1,662 Bytes
580be01
 
 
 
 
 
9523dfb
580be01
9523dfb
580be01
 
9523dfb
580be01
 
 
9523dfb
580be01
 
 
 
 
 
 
 
 
 
9523dfb
580be01
 
 
 
 
 
 
 
 
 
9523dfb
580be01
 
 
 
 
9523dfb
580be01
 
472da27
580be01
 
 
 
 
 
 
472da27
580be01
 
ac572c7
580be01
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
import numpy as np
from keras.models import load_model
import tensorflow as tf
from tensorflow.keras.preprocessing import image
import matplotlib.pyplot as plt
import os
import streamlit as st
from styling import footer

st.cache(allow_output_mutation=True)
st.title("TB Image Classifier")

# loading model
model = load_model('tb_model.h5')
# loading the imaage

file = st.file_uploader(
    "Upload the image",
    type=["png", "jpg"],
    accept_multiple_files=False,
    key=None,
    help=None,
    on_change=None,
    args=None,
    kwargs=None,
)

run = st.button(
    "Make Prediction", key=None, help=None, on_click=None, args=None, kwargs=None
)
st.subheader("This app classifies an x-ray image if it has TB or not")
# image laoder
def load_image(img_path, img_size, show=False):
    img = image.load_img(img_path, target_size=img_size)
    img_tensor = image.img_to_array(img)
    img_tensor = np.expand_dims(img_tensor, axis=0)  # expanding image tensor
    img_tensor = img_tensor / 255.0  # scaling the image_T

    if show:
        plt.imshow(img_tensor[0])
        plt.axis("off")
        plt.show()
    return img_tensor


img_size = (300, 300)
#img_path = "inference image from medscape.jpg"

classes = ["Negative", "Positive"]#["Normal", "Tuberculosis"]
if __name__ == "__main__":
    ## load img
    footer()
    if run == True:
        if file is not None:
            img = load_image(file, img_size)
            pred = model.predict(img)
            output = classes[round(pred[0][0])]
            st.subheader(f"The image is {output} for TB")
        else:
            st.write("Please upload an image first")

            # st.image(file)