Spaces:
Sleeping
Sleeping
Delete pages/ml_reviews_class.py
Browse files- pages/ml_reviews_class.py +0 -48
pages/ml_reviews_class.py
DELETED
@@ -1,48 +0,0 @@
|
|
1 |
-
from sklearn.feature_extraction.text import CountVectorizer
|
2 |
-
from sklearn.linear_model import LogisticRegression
|
3 |
-
import re
|
4 |
-
import string
|
5 |
-
import pickle
|
6 |
-
import streamlit as st
|
7 |
-
|
8 |
-
# Функция очистки текста
|
9 |
-
def clean(text):
|
10 |
-
text = text.lower() # нижний регистр
|
11 |
-
text = re.sub(r'http\S+', " ", text) # удаляем ссылки
|
12 |
-
text = re.sub(r'@\w+',' ',text) # удаляем упоминания пользователей
|
13 |
-
text = re.sub(r'#\w+', ' ', text) # удаляем хэштеги
|
14 |
-
text = re.sub(r'\d+', ' ', text) # удаляем числа
|
15 |
-
text = text.translate(str.maketrans('', '', string.punctuation))
|
16 |
-
return text
|
17 |
-
|
18 |
-
# Загрузка весов модели
|
19 |
-
|
20 |
-
model_filename = '/home/nika/ds-phase-2/10-nlp/model_weights.pkl'
|
21 |
-
with open(model_filename, 'rb') as file:
|
22 |
-
model = pickle.load(file)
|
23 |
-
|
24 |
-
# Загрузка весов векторизатора
|
25 |
-
vectorizer = CountVectorizer()
|
26 |
-
vectorizer_filename = '/home/nika/ds-phase-2/10-nlp/vectorizer_weights.pkl'
|
27 |
-
with open(vectorizer_filename, 'rb') as file:
|
28 |
-
vectorizer = pickle.load(file)
|
29 |
-
|
30 |
-
# Само приложение
|
31 |
-
|
32 |
-
st.title("CritiSense")
|
33 |
-
st.subheader("Movie Review Sentiment Analyzer")
|
34 |
-
st.write("CritiSense is a powerful app that analyzes the sentiment of movie reviews.")
|
35 |
-
st.write("Whether you want to know if a review is positive or negative, CritiSense has got you covered.")
|
36 |
-
st.write("Just enter the review, and our app will provide you with instant sentiment analysis.")
|
37 |
-
st.write("Make informed decisions about movies with CritiSense!")
|
38 |
-
user_review = st.text_input("Enter your review:", "")
|
39 |
-
user_review_clean = clean(user_review)
|
40 |
-
user_features = vectorizer.transform([user_review_clean])
|
41 |
-
prediction = model.predict(user_features)
|
42 |
-
|
43 |
-
st.write("Review:", user_review)
|
44 |
-
|
45 |
-
if prediction == 1:
|
46 |
-
st.markdown("<p style='color: green;'>Sentiment: Positive</p>", unsafe_allow_html=True)
|
47 |
-
else:
|
48 |
-
st.markdown("<p style='color: red;'>Sentiment: Negative</p>", unsafe_allow_html=True)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|