File size: 1,681 Bytes
eb91edf
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
49
50
51
52
53
54
55
56
57
58
59
import pickle

import streamlit as st

from preprocessing import data_preprocessing

# Load preprocessing steps
with open("vectorizer.pkl", "rb") as f:
    logreg_vectorizer = pickle.load(f)

# Load trained model
with open("logreg_model.pkl", "rb") as f:
    logreg_predictor = pickle.load(f)


# Define function for preprocessing input text
@st.cache
def preprocess_text(text):
    # Apply preprocessing steps (cleaning, tokenization, vectorization)
    clean_text = data_preprocessing(
        text
    )  # Assuming data_preprocessing is your preprocessing function
    print("Clean text ", clean_text)
    vectorized_text = vectorizer.transform([" ".join(clean_text)])
    return vectorized_text


# Define function for making predictions
@st.cache
def predict_sentiment(text):
    # Preprocess input text
    processed_text = preprocess_text(text)
    # Make prediction
    prediction = logreg_predictor.predict(processed_text)
    return prediction


st.sidebar.title("Model Selection")
model_type = st.sidebar.radio("Select Model Type", ["Classic ML", "LSTM", "BERT"])
st.title("Review Prediction")

# Streamlit app code
st.title("Sentiment Analysis with Logistic Regression")
text_input = st.text_input("Enter your review:")
if st.button("Predict"):
    if model_type == "Classic ML":
        prediction = predict_sentiment(text_input)
    elif model_type == "LSTM":
        prediction = 1
    elif model_type == "BERT":
        prediction = 1

    if prediction == 1:
        st.write("prediction")
        st.write("Отзыв положительный")
    elif prediction == 0:
        st.write("prediction")
        st.write("Отзыв отрицательный")