-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathwebapp.py
More file actions
executable file
·128 lines (106 loc) · 3.28 KB
/
Copy pathwebapp.py
File metadata and controls
executable file
·128 lines (106 loc) · 3.28 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
import seaborn as sns
import numpy as np
import matplotlib.pyplot as plt
import pandas as pd
import seaborn as sns
import re,nltk,json
import pickle as pk
from sklearn.feature_extraction.text import TfidfVectorizer
from nltk.corpus import stopwords
stop_words = set(stopwords.words("english"))
from nltk.stem import WordNetLemmatizer
from sklearn.feature_extraction.text import TfidfVectorizer
from sklearn.model_selection import train_test_split
from sklearn.neighbors import KNeighborsClassifier
from sklearn.ensemble import RandomForestClassifier, AdaBoostClassifier
from sklearn.naive_bayes import MultinomialNB
from sklearn.svm import SVC
# Warnings
import warnings
warnings.simplefilter(action='ignore', category=FutureWarning)
import streamlit as st
from keras.models import load_model
model1 = pk.load(open('DT_model.sav', 'rb'))
model2 = pk.load(open('BetterModel.sav', 'rb'))
st.markdown(
"""
<style>
.header-style {
font-size:25px;
font-family:sans-serif;
position:absolute;
text-align: center;
color: 032131;
top: 0px;
}
</style>
""",
unsafe_allow_html=True
)
st.markdown(
"""
<style>
.font-style {
font-size:20px;
font-family:sans-serif;
}
</style>
""",
unsafe_allow_html=True
)
# st.markdown(
# "<p class="header-style">Student's Anxiety/Depression Detection Webapp</p>",
# unsafe_allow_html=True
# )
st.header("Student's Anxiety/Depression Detection Webapp")
st.text("")
st.text("")
st.image('image.jpg',width=700)
#dataset loading
df = pd.read_excel('dataset.xlsx')
df = df[:3000]
df = df.sample(frac = 1)
df.dropna()
lm = WordNetLemmatizer()
nltk.download('wordnet')
def text_transformation(col):
corpus = []
for token in col:
alphabet = re.sub('[^a-zA-Z]',' ',str(token))
alphabet = alphabet.lower()
alphabet = alphabet.split()
a_lemmas = [lm.lemmatize(word) for word in alphabet if word not in stop_words]
corpus.append(' '.join(str(x) for x in a_lemmas))
return corpus
df['cleaned'] = text_transformation(df['text'])
# Feature Extraction
X = df.cleaned
y = df.label.astype(int)
vect = TfidfVectorizer(max_features = 20000 , lowercase=False , ngram_range=(1,2),use_idf = True)
X_tfidf =vect.fit_transform(X).toarray()
def text_cl(raw_text):
alphabet = re.sub('[^a-zA-Z]',' ',str(raw_text))
alphabet = alphabet.lower()
alphabet = alphabet.split()
a_lemmas = [lm.lemmatize(word) for word in alphabet if word not in stop_words]
cleant = ' '.join(str(x) for x in a_lemmas)
return cleant
def Anxiety_detection(text):
# column_1, column_2,column_3= st.beta_columns(3)
column_1, column_2 = st.beta_columns(2)
result1 = model1.predict(vect.transform([text]).toarray())[0]
# result2 = model2.predict(vect.transform([text]).toarray())[0]
column_1.write("Model Prediction: ")
if result1 == 1:
column_2.write("Anxiety/Depression")
if result1 == 0:
column_2.write("Normal")
# if result2 == 1:
# column_3.write("Anxiety/Depression")
# if result2 == 0:
# column_3.write("Normal")
user_text = st.text_input("Enter a Sentence")
if user_text is not None:
cleaned_text = text_cl(user_text)
if st.button('Detect'):
Anxiety_detection(cleaned_text)