Spaces:
Build error
Build error
Update app.py
Browse files
app.py
CHANGED
|
@@ -5,13 +5,41 @@ import streamlit.components.v1 as components
|
|
| 5 |
from sklearn.feature_extraction.text import CountVectorizer
|
| 6 |
from sklearn.model_selection import train_test_split
|
| 7 |
import pandas as pd
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 8 |
# Separate target and feature column in X and y variable
|
| 9 |
df = pd.read_csv('stress.csv')
|
| 10 |
# X will be the features
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 11 |
X = np.array(df["text"])
|
| 12 |
|
| 13 |
# y will be the target variable
|
| 14 |
y = np.array(df["label"])
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 15 |
cv = CountVectorizer()
|
| 16 |
# Load the pickled model
|
| 17 |
|
|
@@ -40,7 +68,7 @@ def app_design():
|
|
| 40 |
features = text # add features according to notebook
|
| 41 |
|
| 42 |
# Make a prediction when the user clicks the "Predict" button
|
| 43 |
-
if st.button('Predict
|
| 44 |
predicted_value = model_prediction(features)
|
| 45 |
if predicted_value == "['Stress']":
|
| 46 |
st.success("Your message contains Stress")
|
|
|
|
| 5 |
from sklearn.feature_extraction.text import CountVectorizer
|
| 6 |
from sklearn.model_selection import train_test_split
|
| 7 |
import pandas as pd
|
| 8 |
+
import nltk
|
| 9 |
+
import re
|
| 10 |
+
nltk.download('stopwords')
|
| 11 |
+
stemmer = nltk.SnowballStemmer("english")
|
| 12 |
+
from nltk.corpus import stopwords
|
| 13 |
+
import string
|
| 14 |
+
stopword=set(stopwords.words('english'))
|
| 15 |
# Separate target and feature column in X and y variable
|
| 16 |
df = pd.read_csv('stress.csv')
|
| 17 |
# X will be the features
|
| 18 |
+
def clean(text):
|
| 19 |
+
text = str(text).lower()
|
| 20 |
+
text = re.sub('\[.*?\]', '', text)
|
| 21 |
+
text = re.sub('https?://\S+|www\.\S+', '', text)
|
| 22 |
+
text = re.sub('<.*?>+', '', text)
|
| 23 |
+
text = re.sub('[%s]' % re.escape(string.punctuation), '', text)
|
| 24 |
+
text = re.sub('\n', '', text)
|
| 25 |
+
text = re.sub('\w*\d\w*', '', text)
|
| 26 |
+
text = [word for word in text.split(' ') if word not in stopword]
|
| 27 |
+
text=" ".join(text)
|
| 28 |
+
text = [stemmer.stem(word) for word in text.split(' ')]
|
| 29 |
+
text=" ".join(text)
|
| 30 |
+
return text
|
| 31 |
+
|
| 32 |
+
|
| 33 |
+
df["text"] = df["text"].apply(clean)
|
| 34 |
X = np.array(df["text"])
|
| 35 |
|
| 36 |
# y will be the target variable
|
| 37 |
y = np.array(df["label"])
|
| 38 |
+
|
| 39 |
+
|
| 40 |
+
|
| 41 |
+
df["text"] = df["text"].apply(clean)
|
| 42 |
+
|
| 43 |
cv = CountVectorizer()
|
| 44 |
# Load the pickled model
|
| 45 |
|
|
|
|
| 68 |
features = text # add features according to notebook
|
| 69 |
|
| 70 |
# Make a prediction when the user clicks the "Predict" button
|
| 71 |
+
if st.button('Predict Stress'):
|
| 72 |
predicted_value = model_prediction(features)
|
| 73 |
if predicted_value == "['Stress']":
|
| 74 |
st.success("Your message contains Stress")
|