yashpat85 commited on
Commit
f9b62aa
1 Parent(s): cd85bdd

Upload 3 files

Browse files
Files changed (3) hide show
  1. Home.py +83 -0
  2. Prediction.py +14 -0
  3. requirements.txt +5 -0
Home.py ADDED
@@ -0,0 +1,83 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import streamlit as st
2
+ import pickle
3
+ from Prediction import Prediction
4
+ from transformers import TFAutoModel
5
+
6
+
7
+
8
+ # resnet_model = pickle.load(open('models/ResNet01.pkl','rb'))
9
+ cnn_model = pickle.load(open('models/CNNModel2.pkl','rb'))
10
+ inc_model = pickle.load(open('models/Inception01.pkl','rb'))
11
+ resnet_model = TFAutoModel.from_pretrained("yashpat85/ResNet01")
12
+
13
+
14
+ def show_error_popup(message):
15
+ st.error(message, icon="🚨")
16
+
17
+ st.set_page_config(layout="wide")
18
+
19
+ st.title('Kidney Disease Classification using CNN')
20
+ st.markdown('By 22DCS079 & 22DCS085')
21
+
22
+ st.header('Add Ct Scan Image')
23
+
24
+ uploaded_file = st.file_uploader("Choose a ct scan image", type=["jpg", "png", "jpeg"])
25
+
26
+ st.header("Available Models")
27
+ option = st.selectbox(
28
+ "Available Models",
29
+ ("ResNet", "CNN","InceptionNet"),
30
+ )
31
+
32
+ pm = Prediction()
33
+
34
+ col1, col2= st.columns(2)
35
+
36
+ if uploaded_file is not None:
37
+ with col1:
38
+ image_data = uploaded_file.read()
39
+ st.image(image_data, caption="Uploaded Image")
40
+ with col2:
41
+ if option=="CNN":
42
+ p = pm.predict_image(cnn_model, image_data)
43
+ elif option=="ResNet":
44
+ p = pm.predict_image(resnet_model, image_data)
45
+ elif option=="InceptionNet":
46
+ p = pm.predict_image(inc_model, image_data)
47
+ else:
48
+ p = "Other Models are still under training due to overfitting"
49
+
50
+ print(p)
51
+
52
+ if p=='Normal':
53
+ st.markdown("""
54
+ <style>
55
+ .big-font {
56
+ display: flex;
57
+ align-items:center;
58
+ justify-content: center;
59
+ font-size:50px !important;
60
+ color:green;
61
+ height: 50vh;
62
+ }
63
+ </style>
64
+ """, unsafe_allow_html=True)
65
+
66
+ st.markdown(f'<div class="big-font">{p}</div>', unsafe_allow_html=True)
67
+ else:
68
+ st.markdown("""
69
+ <style>
70
+ .big-font {
71
+ display: flex;
72
+ align-items:center;
73
+ justify-content: center;
74
+ font-size:50px !important;
75
+ color:red;
76
+ height: 50vh;
77
+ }
78
+ </style>
79
+ """, unsafe_allow_html=True)
80
+
81
+ st.markdown(f'<div class="big-font">{p}</div>', unsafe_allow_html=True)
82
+ else:
83
+ show_error_popup("Please Upload Image...")
Prediction.py ADDED
@@ -0,0 +1,14 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import numpy as np
2
+ import tensorflow as tf
3
+
4
+
5
+ class Prediction:
6
+ def predict_image(self, model, img):
7
+ img = tf.image.decode_jpeg(img, channels=3)
8
+ resize = tf.image.resize(img, (224,224))
9
+ yhat = model.predict(np.expand_dims(resize/255, 0))
10
+ max_index = np.argmax(yhat)
11
+ print(yhat)
12
+ op_d = {0:'Cyst',1:'Normal',2:'Stone',3:'Tumor'}
13
+ return op_d[max_index]
14
+
requirements.txt ADDED
@@ -0,0 +1,5 @@
 
 
 
 
 
 
1
+ numpy==1.26.4
2
+ pandas==2.2.2
3
+ tensorflow==2.17.0
4
+ matplotlib==3.9.2
5
+ streamlit==1.37.1