File size: 1,952 Bytes
e3a9602
d8146a1
 
 
 
7a5f863
 
d8146a1
 
 
 
 
 
 
 
 
 
 
 
da3ceaa
d8146a1
 
 
 
 
da3ceaa
d8146a1
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
from sklearn.feature_extraction.text import CountVectorizer
from sklearn.linear_model import LogisticRegression
import re
import string
import pickle
import streamlit as st

# Функция очистки текста
def clean(text):
    text = text.lower() # нижний регистр
    text = re.sub(r'http\S+', " ", text) # удаляем ссылки
    text = re.sub(r'@\w+',' ',text) # удаляем упоминания пользователей
    text = re.sub(r'#\w+', ' ', text) # удаляем хэштеги
    text = re.sub(r'\d+', ' ', text) # удаляем числа
    text = text.translate(str.maketrans('', '', string.punctuation))
    return text

# Загрузка весов модели

model_filename = 'model_weights.pkl'
with open(model_filename, 'rb') as file:
    model = pickle.load(file)

# Загрузка весов векторизатора
vectorizer = CountVectorizer()
vectorizer_filename = 'vectorizer_weights.pkl'
with open(vectorizer_filename, 'rb') as file:
    vectorizer = pickle.load(file)

# Само приложение  

st.title("CritiSense")
st.subheader("Movie Review Sentiment Analyzer")
st.write("CritiSense is a powerful app that analyzes the sentiment of movie reviews.") 
st.write("Whether you want to know if a review is positive or negative, CritiSense has got you covered.") 
st.write("Just enter the review, and our app will provide you with instant sentiment analysis.")
st.write("Make informed decisions about movies with CritiSense!")
user_review = st.text_input("Enter your review:", "")
user_review_clean = clean(user_review)
user_features = vectorizer.transform([user_review_clean])
prediction = model.predict(user_features)

st.write("Review:", user_review)

if prediction == 1:
    st.markdown("<p style='color: green;'>Sentiment: Positive</p>", unsafe_allow_html=True)
else:
    st.markdown("<p style='color: red;'>Sentiment: Negative</p>", unsafe_allow_html=True)