Sibinraj commited on
Commit
d42fc4d
·
1 Parent(s): 2ece94f

Delete app.py

Browse files
Files changed (1) hide show
  1. app.py +0 -167
app.py DELETED
@@ -1,167 +0,0 @@
1
- import pickle
2
- import numpy as np
3
- import streamlit as st
4
- import cv2
5
- import tensorflow as tf
6
- from tqdm import tqdm
7
- from PIL import Image
8
- import os
9
- from tensorflow.keras.preprocessing import sequence
10
- from tensorflow.keras.saving import load_model
11
-
12
- st.title("DL-Classifier")
13
-
14
- task1 = st.selectbox('Select One',("Choose any","Sentiment Classification", 'Tumor Detection'))
15
-
16
-
17
- #choosing tumor detection
18
- #CNN
19
- if task1=="Tumor Detection":
20
- st.subheader("Tumor Detection")
21
- model_path = os.path.join(os.getcwd(), 'cnn_model.h5')
22
- cnn_model = load_model(model_path)
23
-
24
- img =st.file_uploader("choose the image",type=('jpg','jpeg','png'))
25
- def cnn_make_prediction(img,cnn_model):
26
- img=Image.open(img)
27
- img=img.resize((128,128))
28
- img=np.array(img)
29
- input_img = np.expand_dims(img, axis=0)
30
- res = cnn_model.predict(input_img)
31
- if res:
32
- return"Tumor"
33
- else:
34
- return"No Tumor"
35
- if img is not None:
36
- st.image(img, caption="Uploaded Image.", use_column_width=False, width=200)
37
- st.write("")
38
-
39
- if st.button("Detect Tumor"):
40
- result =cnn_make_prediction(img, cnn_model)
41
- st.subheader("Tumor Detection Result")
42
- st.write(f"**{result}**")
43
-
44
-
45
- #choosing classification
46
-
47
-
48
- if task1=="Sentiment Classification":
49
- st.subheader("Sentiment Classification")
50
- clss_model= st.radio("Select Classification Model:",("RNN","DNN","Backpropagation",'Perceptron','LSTM'))
51
- select_model=None
52
-
53
- if clss_model=="RNN":
54
-
55
- model_path = os.path.join(os.getcwd(), 'rnn_model.h5')
56
- rnn_model = load_model(model_path)
57
- with open("rnn_tokeniser.pkl",'rb') as tokeniser_file:
58
- rnn_tokeniser=pickle.load(tokeniser_file)
59
-
60
- st.subheader('RNN Spam Classification')
61
-
62
- input=st.text_input("Enter your message here:")
63
- def rnn_pred(input):
64
- max_length=10
65
- encoded_test = rnn_tokeniser.texts_to_sequences(input)
66
- padded_test = tf.keras.preprocessing.sequence.pad_sequences(encoded_test, maxlen=max_length, padding='post')
67
- predict= (rnn_model.predict(padded_test) > 0.5).astype("int32")
68
- if predict:
69
- return "Spam "
70
- else:
71
- return "Not Spam"
72
- if st.button('Check'):
73
- pred=rnn_pred([input])
74
- st.write(pred)
75
-
76
- if clss_model=='Perceptron':
77
- with open("perceptron_model_saved.pkl",'rb') as model_file:
78
- percep_model=pickle.load(model_file)
79
- with open('perceptron_tokeniser_saved.pkl','rb') as model_file:
80
- percep_token=pickle.load(model_file)
81
- st.subheader('Perceptron Spam Classification')
82
- input= st.text_input("Enter your text here")
83
-
84
- def percep_pred(input):
85
- encoded_test_p = percep_token.texts_to_sequences([input])
86
- padded_test_p = tf.keras.preprocessing.sequence.pad_sequences(encoded_test_p, maxlen=10)
87
- predict_p= percep_model.predict(padded_test_p)
88
- if predict_p:
89
- return "Spam"
90
- else:
91
- return "Not Spam"
92
- if st.button("Check"):
93
- pred=percep_pred([input])
94
- st.write(pred)
95
-
96
-
97
- if clss_model=="Backpropagation":
98
- with open('bp_model.pkl','rb') as model_file:
99
- bp_model=pickle.load(model_file)
100
- with open('backrpop_tokeniser.pkl','rb') as model_file:
101
- bp_tokeniser=pickle.load(model_file)
102
- st.subheader('Backpropagation Spam Classification')
103
- input= st.text_input("Enter your text here")
104
-
105
-
106
- def back_pred(input):
107
- encoded_test = bp_tokeniser.texts_to_sequences([input])
108
- padded_test = tf.keras.preprocessing.sequence.pad_sequences(encoded_test, maxlen=10)
109
- predict= bp_model.predict(padded_test)
110
- if predict:
111
- return "Spam"
112
- else:
113
- return "Not Spam"
114
- if st.button("Check"):
115
- pred=back_pred([input])
116
- st.write(pred)
117
-
118
- if clss_model=="DNN":
119
-
120
- model_path = os.path.join(os.getcwd(), 'dnn_model.h5')
121
- dnn_model = load_model(model_path)
122
-
123
- with open("dnn_tokeniser.pkl",'rb') as file:
124
- dnn_tokeniser=pickle.load(file)
125
- st.subheader('DNN Spam Classification')
126
- input= st.text_input("Enter your text here")
127
-
128
- def dnn_pred(input):
129
- encoded_test = dnn_tokeniser.texts_to_sequences([input])
130
- padded_test = tf.keras.preprocessing.sequence.pad_sequences(encoded_test, maxlen=500)
131
- predict= dnn_model.predict(padded_test)
132
- if predict:
133
- return "Spam"
134
- else:
135
- return "Not Spam"
136
- if st.button('Check'):
137
- pred=dnn_pred([input])
138
- st.write(pred)
139
-
140
-
141
- if clss_model=="LSTM":
142
- model_path = os.path.join(os.getcwd(), 'lstm_model.h5')
143
- lstm_model = load_model(model_path)
144
-
145
- with open("lstm_tokeniser.pkl",'rb') as file:
146
- lstm_tokeniser=pickle.load(file)
147
- st.subheader('Movie Review Classification')
148
- inp=st.text_area("Enter your review")
149
- def lstm_make_predictions(inp, model):
150
- inp = lstm_tokeniser.texts_to_sequences(inp)
151
- inp = sequence.pad_sequences(inp, maxlen=500)
152
- res = (model.predict(inp) > 0.5).astype("int32")
153
- if res:
154
- return "Negative"
155
- else:
156
- return "Positive"
157
-
158
-
159
- if st.button('Check'):
160
- pred = lstm_make_predictions([inp], lstm_model)
161
- st.write(pred)
162
-
163
-
164
-
165
-
166
-
167
-