perman2011 commited on
Commit
5708132
1 Parent(s): cd647f0

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +37 -3
app.py CHANGED
@@ -13,8 +13,6 @@ nltk.download('punkt')
13
 
14
  import streamlit as st
15
 
16
- import functions
17
-
18
 
19
  # Preprocess function
20
  from nltk.corpus import stopwords
@@ -72,10 +70,46 @@ model_NB = joblib.load(model_NB_path)
72
  model_LR_path = './model_LR.sav'
73
  model_LR = joblib.load(model_LR_path)
74
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
75
 
76
  text = st.text_area('Enter some text !!! (English text : D )')
77
  if text:
78
- out = functions.sentiment_analysis_LR(text)
79
  if out == 0:
80
  out = 'negative'
81
  st.json(out)
 
13
 
14
  import streamlit as st
15
 
 
 
16
 
17
  # Preprocess function
18
  from nltk.corpus import stopwords
 
70
  model_LR_path = './model_LR.sav'
71
  model_LR = joblib.load(model_LR_path)
72
 
73
+ def sentiment_analysis_LR(input):
74
+ # Assuming you have a Logistic Regression model and TfidfVectorizer in the pipeline
75
+ input = preprocess_text(input)
76
+
77
+ vectorizer = model_LR.named_steps['tfidfvectorizer']
78
+ lr_classifier = model_LR.named_steps['logisticregression']
79
+
80
+ # Transform the user input using the TF-IDF vectorizer
81
+ user_input_tfidf = vectorizer.transform([input])
82
+
83
+ # Make predictions
84
+ user_pred = lr_classifier.predict(user_input_tfidf)
85
+
86
+ # Display the prediction
87
+ if user_pred[0] == 0:
88
+ return 0
89
+ else:
90
+ return 1
91
+
92
+ def sentiment_analysis_NB(input):
93
+ input = preprocess_text(input)
94
+
95
+ vectorizer = model_NB.named_steps['tfidf']
96
+ nb_classifier = model_NB.named_steps['nb']
97
+
98
+ # Transform the user input using the TF-IDF vectorizer
99
+ user_input_tfidf = vectorizer.transform([input])
100
+
101
+ # Make predictions
102
+ user_pred = nb_classifier.predict(user_input_tfidf)
103
+
104
+ # Display the prediction
105
+ if user_pred[0] == 0:
106
+ return 0
107
+ else:
108
+ return 1
109
 
110
  text = st.text_area('Enter some text !!! (English text : D )')
111
  if text:
112
+ out = sentiment_analysis_LR(text)
113
  if out == 0:
114
  out = 'negative'
115
  st.json(out)