Abhinand2001 commited on
Commit
3dc0589
·
1 Parent(s): 346cacf

Upload 13 files

Browse files
assignment.py ADDED
@@ -0,0 +1,156 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import pandas as pd
2
+ import streamlit as st
3
+ import numpy as np
4
+ import tensorflow as tf
5
+ from PIL import Image
6
+ import pickle
7
+
8
+
9
+ st.header('Demo')
10
+ task = st.selectbox('Select Task', ["Select One",'Sentiment Classification', 'Tumor Detection'])
11
+
12
+
13
+ if task == "Tumor Detection":
14
+ def cnn(img, model):
15
+ img = Image.open(img)
16
+ img = img.resize((128, 128))
17
+ img = np.array(img)
18
+ input_img = np.expand_dims(img, axis=0)
19
+ res = model.predict(input_img)
20
+ if res:
21
+ return "Tumor Detected"
22
+ else:
23
+ return "No Tumor"
24
+
25
+ cnn_model = tf.keras.models.load_model("tumor_detection_model.h5")
26
+ uploaded_file = st.file_uploader("Choose a file", type=["jpg", "jpeg", "png"])
27
+ if uploaded_file is not None:
28
+ st.image(uploaded_file, caption="Uploaded Image", use_column_width=True)
29
+ if st.button("Submit"):
30
+ result=cnn(uploaded_file, cnn_model)
31
+ st.write(result)
32
+
33
+
34
+ elif task == "Sentiment Classification":
35
+ types = ["Perceptron","BackPropagation", "RNN","DNN", "LSTM"]
36
+ input_text2 = st.radio("Select", types, horizontal=True)
37
+
38
+ if input_text2 == "Perceptron":
39
+ with open("ppn_model.pkl",'rb') as file:
40
+ perceptron = pickle.load(file)
41
+ with open("ppn_tokeniser.pkl",'rb') as file:
42
+ ppn_tokeniser = pickle.load(file)
43
+
44
+ def ppn_make_predictions(inp, model):
45
+ encoded_inp = ppn_tokeniser.texts_to_sequences([inp])
46
+ padded_inp = tf.keras.preprocessing.sequence.pad_sequences(encoded_inp, maxlen=500)
47
+ res = model.predict(padded_inp)
48
+ if res:
49
+ return "Negative"
50
+ else:
51
+ return "Positive"
52
+
53
+ st.subheader('Movie Review Classification using Perceptron')
54
+ inp = st.text_area('Enter message')
55
+ if st.button('Check'):
56
+ pred = ppn_make_predictions([inp], perceptron)
57
+ st.write(pred)
58
+
59
+ if input_text2 == "BackPropagation":
60
+ with open("bp_model.pkl",'rb') as file:
61
+ backprop = pickle.load(file)
62
+ with open("bp_tokeniser.pkl",'rb') as file:
63
+ bp_tokeniser = pickle.load(file)
64
+
65
+ def bp_make_predictions(inp, model):
66
+ encoded_inp = bp_tokeniser.texts_to_sequences([inp])
67
+ padded_inp = tf.keras.preprocessing.sequence.pad_sequences(encoded_inp, maxlen=500)
68
+ res = model.predict(padded_inp)
69
+ if res:
70
+ return "Negative"
71
+ else:
72
+ return "Positive"
73
+
74
+ st.subheader('Movie Review Classification using BackPropagation')
75
+ inp = st.text_area('Enter message')
76
+ if st.button('Check'):
77
+ pred = bp_make_predictions([inp], backprop)
78
+ st.write(pred)
79
+
80
+
81
+ elif input_text2 == "RNN":
82
+ with open("spam_model.pkl", 'rb') as model_file:
83
+ rnn_model=pickle.load(model_file)
84
+ with open("spam_tokeniser.pkl", 'rb') as model_file:
85
+ rnn_tokeniser=pickle.load(model_file)
86
+
87
+ def rnn_make_predictions(inp, model):
88
+ encoded_inp = rnn_tokeniser.texts_to_sequences([inp])
89
+ padded_inp = tf.keras.preprocessing.sequence.pad_sequences(encoded_inp, maxlen=10, padding='post')
90
+ res = (model.predict(padded_inp) > 0.5).astype("int32")
91
+ if res:
92
+ return "Spam"
93
+ else:
94
+ return "Ham"
95
+
96
+ st.subheader('Spam message Classification using RNN')
97
+ input = st.text_area("Give message")
98
+ if st.button('Check'):
99
+ pred = rnn_make_predictions([input], rnn_model)
100
+ st.write(pred)
101
+
102
+
103
+
104
+ elif input_text2 == "DNN":
105
+ with open("dnn_model.pkl",'rb') as file:
106
+ dnn_model = pickle.load(file)
107
+ with open("dnn_tokeniser.pkl",'rb') as file:
108
+ dnn_tokeniser = pickle.load(file)
109
+
110
+ def dnn_make_predictions(inp, model):
111
+
112
+ inp = dnn_tokeniser.texts_to_sequences([inp])
113
+ inp = tf.keras.preprocessing.sequence.pad_sequences(inp, maxlen=500)
114
+ res = model.predict([inp])
115
+ if res:
116
+ return "Negative"
117
+ else:
118
+ return "Positive"
119
+
120
+ st.subheader('Movie Review Classification using DNN')
121
+ inp = st.text_area('Enter message')
122
+ if st.button('Check'):
123
+ pred = dnn_make_predictions([inp], dnn_model)
124
+ st.write(pred)
125
+
126
+
127
+
128
+ elif input_text2 == "LSTM":
129
+ with open("lstm_model.pkl",'rb') as file:
130
+ lstm_model = pickle.load(file)
131
+
132
+ with open("lstm_tokeniser.pkl",'rb') as file:
133
+ lstm_tokeniser = pickle.load(file)
134
+
135
+ def lstm_make_predictions(inp, model):
136
+ inp = lstm_tokeniser.texts_to_sequences([inp])
137
+ inp = tf.keras.preprocessing.sequence.pad_sequences(inp, maxlen=500)
138
+ res = (model.predict(inp) > 0.5).astype("int32")
139
+ if res:
140
+ return "Negative"
141
+ else:
142
+ return "Positive"
143
+ st.subheader('Movie Review Classification using LSTM')
144
+ inp = st.text_area('Enter message')
145
+ if st.button('Check'):
146
+ pred = lstm_make_predictions([inp], lstm_model)
147
+ st.write(pred)
148
+
149
+
150
+
151
+
152
+
153
+
154
+
155
+
156
+
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:e5b5110d992f43b2be8ae7213e998f5ed8364e0ea50160bf27a07f8eda3071b5
3
+ size 4992453
dnn_model.pkl ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:9ce21a6e8697e9ad0f9e6b498af66a3b2bcd1ec166967bb2127f20c5217c8b62
3
+ size 445643
dnn_tokeniser.pkl ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:9669cc4a7b1a8b6c58f4a41d23044f68f9f4b9e4581796a2c677bfd115f437c7
3
+ size 4534143
lstm_model.pkl ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:82ba0fdcd26b5d676861aa045bfdeff5358040cadd386db6b2e01266fcd26512
3
+ size 41216539
lstm_tokeniser.pkl ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:1741a71670e2bc8397a86ea71f7f6caa146b61bb050cf5e813cdf3ffc22004e8
3
+ size 4534143
ppn_model.pkl ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:6b2f35d300e2e1e62ba318a5c87325ceaec298f9acd7d8e1d367e663ba049715
3
+ size 2267
ppn_tokeniser.pkl ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:37aa7ac9ab0c53abd1a1062e78cf9c480fcea66189ed01804e30bf4123a93626
3
+ size 4848716
spam_model.pkl ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:13b4fe44be9a489aea7d3b92f011cdbb4e48210d5b59bebd49f7dc1a11420b37
3
+ size 2255782
spam_tokeniser.pkl ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:8ccf3ead030e608406503d2c70eff136b4564b3db13d14f5c8fd290e9a3e6c4e
3
+ size 290462
tumor_detection_model.h5 ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:5bf07748badd8583c2f9a77f3b20d2a0d36c5e9e6440eb398de4e1e1975b6304
3
+ size 391811360
tumor_detection_model.pkl ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:b511ff209422d5b75731fe30d78a6f5b8b4e32e7a04c6c36bfae89a1ee7e65b7
3
+ size 391803384