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("
Sentiment: Positive
", unsafe_allow_html=True) else: st.markdown("Sentiment: Negative
", unsafe_allow_html=True)