Spaces:
Sleeping
Sleeping
Upload 12 files
Browse files- bp_model.pkl +3 -0
- bp_tokeniser.pkl +3 -0
- cnn_model.h5 +3 -0
- dnn_model.h5 +3 -0
- dnn_tokeniser.pkl +3 -0
- lstm_model.h5 +3 -0
- lstm_tokeniser.pkl +3 -0
- ppn_model.pkl +3 -0
- ppn_tokeniser.pkl +3 -0
- rnn_model.h5 +3 -0
- rnn_tokeniser.pkl +3 -0
- st.py +154 -0
bp_model.pkl
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:2898ac4c9ef15f477f4bd8ac49b1ae1357b92e6d8867b14c0b05ec7a4ea45149
|
| 3 |
+
size 4300
|
bp_tokeniser.pkl
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:68c56c0afcd4c13ccac291859cf6bb44f4c78f9378c6a1f6bd9b9f313cd8e580
|
| 3 |
+
size 4992453
|
cnn_model.h5
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:4c77c24c8acdd3de3dd04e80b3fe114bdc1eec826538b713ab0c2a3400bab2be
|
| 3 |
+
size 391811360
|
dnn_model.h5
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:48e62d61e3e53722cfb1181a65fa4ad9b1d5d54c2da34f7ed881064504916ca6
|
| 3 |
+
size 457224
|
dnn_tokeniser.pkl
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:fc21bf90fe1bf134b8ade78b93d6e14238875adf7f954e47231ff9f6a0d1bb3e
|
| 3 |
+
size 4534143
|
lstm_model.h5
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:207aec2713ec6e86fa02a2f7bc5b1e042bf241e2af26b76fb2a80c5cf0702921
|
| 3 |
+
size 41224696
|
lstm_tokeniser.pkl
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:b1de484d6fe87bf8b6844fb66beab45096d8933e4b6a55ed40118dd82e1b19a8
|
| 3 |
+
size 4534143
|
ppn_model.pkl
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:62fe7b6a7005d5c06fcce7f72252bebca37c3ad923f1ec6555e94388b95bd4ca
|
| 3 |
+
size 2267
|
ppn_tokeniser.pkl
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:32ed1024acf49a6d96a40d5d938c340054302c09f3533f3d3e572a62df9c3719
|
| 3 |
+
size 4848716
|
rnn_model.h5
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:72eec6a6bfe021e27843b74245abea60c295188e1913e1af54aa7564ef02e7b0
|
| 3 |
+
size 2243672
|
rnn_tokeniser.pkl
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:0046c6215e32d084977d5b2aca73448f0fd33d7726be036a8d5e46a5796d59a6
|
| 3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| 4 |
+
from tensorflow.keras.preprocessing import sequence
|
| 5 |
+
import numpy as np
|
| 6 |
+
import cv2
|
| 7 |
+
from PIL import Image
|
| 8 |
+
|
| 9 |
+
|
| 10 |
+
st.title('Classifier')
|
| 11 |
+
task = st.selectbox('Select Task', ['Choose one','Sentiment Classification', 'Tumor Detection'])
|
| 12 |
+
|
| 13 |
+
if task=='Tumor Detection':
|
| 14 |
+
st.subheader('Tumor Detection with CNN')
|
| 15 |
+
# CNN
|
| 16 |
+
cnn_model = tf.keras.models.load_model("cnn_model.h5")
|
| 17 |
+
|
| 18 |
+
def cnn_make_prediction(img,model):
|
| 19 |
+
img=cv2.imread(img)
|
| 20 |
+
img=Image.fromarray(img)
|
| 21 |
+
img=img.resize((128,128))
|
| 22 |
+
img=np.array(img)
|
| 23 |
+
input_img = np.expand_dims(img, axis=0)
|
| 24 |
+
res = model.predict(input_img)
|
| 25 |
+
if res:
|
| 26 |
+
return "Tumor Detected"
|
| 27 |
+
else:
|
| 28 |
+
return "No Tumor Detected"
|
| 29 |
+
|
| 30 |
+
img = st.file_uploader('Upload image', type=['jpeg', 'jpg', 'png'])
|
| 31 |
+
if img!=None:
|
| 32 |
+
img_folder = "data/tumordata/pred/"
|
| 33 |
+
img_path = img_folder+img.name
|
| 34 |
+
st.image(img_path, caption = "Image preview")
|
| 35 |
+
if st.button('Submit'):
|
| 36 |
+
pred = cnn_make_prediction(img_path, cnn_model)
|
| 37 |
+
st.write(pred)
|
| 38 |
+
|
| 39 |
+
|
| 40 |
+
if task=='Sentiment Classification':
|
| 41 |
+
arcs = ['Perceptron', 'Backpropagation', 'DNN', 'RNN', 'LSTM']
|
| 42 |
+
arc = st.radio('Pick one:', arcs, horizontal=True)
|
| 43 |
+
|
| 44 |
+
if arc == arcs[0]:
|
| 45 |
+
# Perceptron
|
| 46 |
+
with open("models/pickles/ppn_model.pkl",'rb') as file:
|
| 47 |
+
perceptron = pickle.load(file)
|
| 48 |
+
with open("models/pickles/ppn_tokeniser.pkl",'rb') as file:
|
| 49 |
+
ppn_tokeniser = pickle.load(file)
|
| 50 |
+
|
| 51 |
+
def ppn_make_predictions(inp, model):
|
| 52 |
+
encoded_inp = ppn_tokeniser.texts_to_sequences([inp])
|
| 53 |
+
padded_inp = sequence.pad_sequences(encoded_inp, maxlen=500)
|
| 54 |
+
res = model.predict(padded_inp)
|
| 55 |
+
if res:
|
| 56 |
+
return "Negative"
|
| 57 |
+
else:
|
| 58 |
+
return "Positive"
|
| 59 |
+
|
| 60 |
+
st.subheader('Movie Review Classification using Perceptron')
|
| 61 |
+
inp = st.text_area('Enter message')
|
| 62 |
+
if st.button('Check'):
|
| 63 |
+
pred = ppn_make_predictions([inp], perceptron)
|
| 64 |
+
st.write(pred)
|
| 65 |
+
|
| 66 |
+
elif arc == arcs[1]:
|
| 67 |
+
# BackPropogation
|
| 68 |
+
with open("models/pickles/bp_model.pkl",'rb') as file:
|
| 69 |
+
backprop = pickle.load(file)
|
| 70 |
+
with open("models/pickles/bp_tokeniser.pkl",'rb') as file:
|
| 71 |
+
bp_tokeniser = pickle.load(file)
|
| 72 |
+
|
| 73 |
+
def bp_make_predictions(inp, model):
|
| 74 |
+
encoded_inp = bp_tokeniser.texts_to_sequences([inp])
|
| 75 |
+
padded_inp = sequence.pad_sequences(encoded_inp, maxlen=500)
|
| 76 |
+
res = model.predict(padded_inp)
|
| 77 |
+
if res:
|
| 78 |
+
return "Negative"
|
| 79 |
+
else:
|
| 80 |
+
return "Positive"
|
| 81 |
+
|
| 82 |
+
st.subheader('Movie Review Classification using Backpropagation')
|
| 83 |
+
inp = st.text_area('Enter message')
|
| 84 |
+
if st.button('Check'):
|
| 85 |
+
pred = bp_make_predictions([inp], backprop)
|
| 86 |
+
st.write(pred)
|
| 87 |
+
|
| 88 |
+
|
| 89 |
+
elif arc == arcs[2]:
|
| 90 |
+
# DNN
|
| 91 |
+
dnn_model = tf.keras.models.load_model("dnn_model.h5")
|
| 92 |
+
with open("models/pickles/dnn_tokeniser.pkl",'rb') as file:
|
| 93 |
+
dnn_tokeniser = pickle.load(file)
|
| 94 |
+
|
| 95 |
+
def dnn_make_predictions(inp, model):
|
| 96 |
+
inp = dnn_tokeniser.texts_to_sequences(inp)
|
| 97 |
+
inp = sequence.pad_sequences(inp, maxlen=500)
|
| 98 |
+
res = (model.predict(inp) > 0.5).astype("int32")
|
| 99 |
+
if res:
|
| 100 |
+
return "Negative"
|
| 101 |
+
else:
|
| 102 |
+
return "Positive"
|
| 103 |
+
|
| 104 |
+
st.subheader('Movie Review Classification using DNN')
|
| 105 |
+
inp = st.text_area('Enter message')
|
| 106 |
+
if st.button('Check'):
|
| 107 |
+
pred = dnn_make_predictions([inp], dnn_model)
|
| 108 |
+
st.write(pred)
|
| 109 |
+
|
| 110 |
+
|
| 111 |
+
elif arc == arcs[3]:
|
| 112 |
+
# RNN
|
| 113 |
+
rnn_model = tf.keras.models.load_model("rnn_model.h5")
|
| 114 |
+
|
| 115 |
+
with open("models/pickles/rnn_tokeniser.pkl",'rb') as file:
|
| 116 |
+
rnn_tokeniser = pickle.load(file)
|
| 117 |
+
|
| 118 |
+
def rnn_make_predictions(inp, model):
|
| 119 |
+
encoded_inp = rnn_tokeniser.texts_to_sequences(inp)
|
| 120 |
+
padded_inp = sequence.pad_sequences(encoded_inp, maxlen=10, padding='post')
|
| 121 |
+
res = (model.predict(padded_inp) > 0.5).astype("int32")
|
| 122 |
+
if res:
|
| 123 |
+
return "Spam"
|
| 124 |
+
else:
|
| 125 |
+
return "Ham"
|
| 126 |
+
|
| 127 |
+
st.subheader('SMS Spam Classification using RNN')
|
| 128 |
+
inp = st.text_area('Enter message')
|
| 129 |
+
if st.button('Check'):
|
| 130 |
+
pred = rnn_make_predictions([inp], rnn_model)
|
| 131 |
+
st.write(pred)
|
| 132 |
+
|
| 133 |
+
|
| 134 |
+
elif arc == arcs[4]:
|
| 135 |
+
# LSTM
|
| 136 |
+
lstm_model = tf.keras.models.load_model("lstm_model.h5")
|
| 137 |
+
|
| 138 |
+
with open("models/pickles/lstm_tokeniser.pkl",'rb') as file:
|
| 139 |
+
lstm_tokeniser = pickle.load(file)
|
| 140 |
+
|
| 141 |
+
def lstm_make_predictions(inp, model):
|
| 142 |
+
inp = lstm_tokeniser.texts_to_sequences(inp)
|
| 143 |
+
inp = sequence.pad_sequences(inp, maxlen=500)
|
| 144 |
+
res = (model.predict(inp) > 0.5).astype("int32")
|
| 145 |
+
if res:
|
| 146 |
+
return "Negative"
|
| 147 |
+
else:
|
| 148 |
+
return "Positive"
|
| 149 |
+
|
| 150 |
+
st.subheader('Movie Review Classification using LSTM')
|
| 151 |
+
inp = st.text_area('Enter message')
|
| 152 |
+
if st.button('Check'):
|
| 153 |
+
pred = lstm_make_predictions([inp], lstm_model)
|
| 154 |
+
st.write(pred)
|