Deevyankar commited on
Commit
8cf34f2
1 Parent(s): 206273c

Added app files

Browse files
Files changed (3) hide show
  1. app.py +86 -0
  2. fmodel.h5 +3 -0
  3. unilogo.png +0 -0
app.py ADDED
@@ -0,0 +1,86 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import numpy as np
2
+ import pandas as pd
3
+ import altair as alt
4
+ from PIL import Image
5
+ import streamlit as st
6
+ import tensorflow as tf
7
+ from itertools import chain
8
+
9
+ col1, col2, col3 = st.columns(3)
10
+
11
+ with col1:
12
+ st.write(' ')
13
+
14
+ with col2:
15
+ st.image("unilogo.png", width=300)
16
+ st.markdown("<h6 style='text-align: center; color: grey;'>University of Technology and Applied Sciences, Muscat</h6>",
17
+ unsafe_allow_html=True)
18
+ st.markdown("<h1 style='text-align: center; color: grey;'>X-RAY Classsifier</h1>",
19
+ unsafe_allow_html=True)
20
+ st.markdown("<h6 style='text-align: center; color: grey;'>DEEVYANKAR AGARWAL</h6>",
21
+ unsafe_allow_html=True)
22
+ st.markdown("<h6 style='text-align: center; color: grey;'>MAATHIR YAHYA ABDULLAH AL HINAI</h6>",
23
+ unsafe_allow_html=True)
24
+ st.markdown("<h6 style='text-align: center; color: grey;'>MAATHIR YAHYA ABDULLAH AL HINAI</h6>",
25
+ unsafe_allow_html=True)
26
+ st.markdown("<h6 style='text-align: center; color: grey;'>MARYAM MOHAMMED HILAL AL-HASHAMI</h6>",
27
+ unsafe_allow_html=True)
28
+ st.markdown("<h6 style='text-align: center; color: grey;'>Shafa NASSER MOHAMMED AL AAMRI</h6>",
29
+ unsafe_allow_html=True)
30
+
31
+ with col3:
32
+ st.write(' ')
33
+
34
+
35
+ file_upload = st.file_uploader("Upload the X-RAY Scan ", type=[
36
+ "png", "jpg", "jpeg", "heic", "tiff", "bmp", "raw"], accept_multiple_files=False)
37
+
38
+
39
+ class_dict = {"0": 'covid19', "1": 'normal', "2": 'pneumonia'}
40
+
41
+ model = tf.keras.models.load_model('fmodel.h5')
42
+
43
+
44
+ def preprocess_image(image_path):
45
+
46
+ image = Image.open(image_path)
47
+
48
+ image = image.resize((224, 224))
49
+ image_array = tf.keras.preprocessing.image.img_to_array(image)
50
+ image_array /= 255.0
51
+ image_array = tf.expand_dims(image_array, 0)
52
+
53
+ return image_array
54
+
55
+
56
+ if file_upload:
57
+
58
+ with open(file_upload.name, "wb") as f:
59
+ f.write(file_upload.getbuffer())
60
+
61
+ saved_path = f"{file_upload.name}"
62
+
63
+ preprocessed_image = preprocess_image(saved_path)
64
+ pred_prob = model.predict(preprocessed_image)
65
+ predicted_class_index = np.argmax(pred_prob, axis=1).item()
66
+ predicted_class = class_dict[f"{predicted_class_index}"]
67
+
68
+ st.write("Predicted Class: ", predicted_class)
69
+
70
+ print(predicted_class_index)
71
+ print(predicted_class)
72
+ print(pred_prob)
73
+
74
+ graph_input = list(chain.from_iterable(pred_prob.tolist()))
75
+ "Plot depicting Class Probabilities"
76
+ source = pd.DataFrame({
77
+ 'Class probability': graph_input,
78
+ 'Class': ["COVID-19", "NORMAL", "PNEUMONIA"]
79
+ })
80
+
81
+ bar_chart = alt.Chart(source).mark_bar().encode(
82
+ y='Class probability:Q',
83
+ x='Class:O',
84
+ )
85
+
86
+ element5 = st.altair_chart(bar_chart, use_container_width=True)
fmodel.h5 ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:4e70e0b9cdc0b0f564c3bed77611d742032c5da5fd58664645f2e8ec883ad6c7
3
+ size 59842536
unilogo.png ADDED