File size: 2,750 Bytes
8cf34f2
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
af42be0
8cf34f2
938ce35
8cf34f2
 
 
 
 
938ce35
8cf34f2
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
import numpy as np
import pandas as pd
import altair as alt
from PIL import Image
import streamlit as st
import tensorflow as tf
from itertools import chain

col1, col2, col3 = st.columns(3)

with col1:
    st.write(' ')

with col2:
    st.image("unilogo.png", width=300)
    st.markdown("<h6 style='text-align: center; color: grey;'>University of Technology and Applied Sciences, Muscat</h6>",
            unsafe_allow_html=True)
    st.markdown("<h1 style='text-align: center; color: grey;'>X-RAY Classsifier</h1>",
                unsafe_allow_html=True)
st.markdown("<h6 style='text-align: center; color: grey;'>Project Supervisor : DEEVYANKAR AGARWAL</h6>",
            unsafe_allow_html=True)
st.markdown("<h6 style='text-align: center; color: grey;'>MALIKA SULTAN ALNAABI</h6>",
            unsafe_allow_html=True)
st.markdown("<h6 style='text-align: center; color: grey;'>MAATHIR YAHYA ABDULLAH AL HINAI</h6>",
            unsafe_allow_html=True)
st.markdown("<h6 style='text-align: center; color: grey;'>MARYAM MOHAMMED HILAL AL-HASHAMI</h6>",
            unsafe_allow_html=True)
st.markdown("<h6 style='text-align: center; color: grey;'>SHIFA NASSER MOHAMMED AL AAMRI</h6>",
            unsafe_allow_html=True)

with col3:
    st.write(' ')


file_upload = st.file_uploader("Upload the X-RAY Scan ", type=[
                               "png", "jpg", "jpeg", "heic", "tiff", "bmp", "raw"], accept_multiple_files=False)


class_dict = {"0": 'covid19', "1": 'normal', "2": 'pneumonia'}

model = tf.keras.models.load_model('fmodel.h5')


def preprocess_image(image_path):

    image = Image.open(image_path)

    image = image.resize((224, 224))
    image_array = tf.keras.preprocessing.image.img_to_array(image)
    image_array /= 255.0
    image_array = tf.expand_dims(image_array, 0)

    return image_array


if file_upload:
    
    with open(file_upload.name, "wb") as f:
        f.write(file_upload.getbuffer())

    saved_path = f"{file_upload.name}"

    preprocessed_image = preprocess_image(saved_path)
    pred_prob = model.predict(preprocessed_image)
    predicted_class_index = np.argmax(pred_prob, axis=1).item()
    predicted_class = class_dict[f"{predicted_class_index}"]

    st.write("Predicted Class: ", predicted_class)

    print(predicted_class_index)
    print(predicted_class)
    print(pred_prob)

    graph_input = list(chain.from_iterable(pred_prob.tolist()))
    "Plot depicting Class Probabilities"
    source = pd.DataFrame({
        'Class probability': graph_input,
        'Class': ["COVID-19", "NORMAL", "PNEUMONIA"]
    })

    bar_chart = alt.Chart(source).mark_bar().encode(
        y='Class probability:Q',
        x='Class:O',
    )

    element5 = st.altair_chart(bar_chart, use_container_width=True)