Spaces:
Runtime error
Runtime error
Upload 6 files
Browse files- pages/ml_reviews_class.py +48 -0
- pages/model_comments_weights.pkl +3 -0
- pages/model_history.pt +3 -0
- pages/model_weights.pkl +3 -0
- pages/vectorizer_comments_weights.pkl +3 -0
- pages/vectorizer_weights.pkl +3 -0
pages/ml_reviews_class.py
ADDED
@@ -0,0 +1,48 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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)
|
pages/model_comments_weights.pkl
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:9a2642dc31855483b855511afc099cd80d65aac75520e8460b01c4164ad48a40
|
3 |
+
size 464784
|
pages/model_history.pt
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:7251915a6188c935eaa9d581c41f03c238a1058d3f7da77b95cd39252af42b13
|
3 |
+
size 551321853
|
pages/model_weights.pkl
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:7b27177e32cde75392fe954cc9ccceb799dc09a65a9144d1c07df9726134e8ec
|
3 |
+
size 1238083
|
pages/vectorizer_comments_weights.pkl
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:e6b8c9839ddfbe2a30d82701c713528ec1012bebe68bf3e156124d163f587c35
|
3 |
+
size 1281514
|
pages/vectorizer_weights.pkl
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:045809c9e4cd5709117634017a3da547cd6a927a0380773dce4811ce0b97e015
|
3 |
+
size 2466402
|