nlp_proj / app.py
Maslov-Artem
Add logreg
9f7701f
raw
history blame
1.23 kB
import pickle
import streamlit as st
from preprocessing import data_preprocessing
# Load preprocessing steps
with open("vectorizer.pkl", "rb") as f:
vectorizer = pickle.load(f)
# Load trained model
with open("logreg_model.pkl", "rb") as f:
logreg = pickle.load(f)
# Define function for preprocessing input text
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
def predict_sentiment(text):
# Preprocess input text
processed_text = preprocess_text(text)
print(preprocess_text)
# Make prediction
prediction = logreg.predict(processed_text)
return prediction
# Streamlit app code
st.title("Sentiment Analysis with Logistic Regression")
text_input = st.text_input("Enter your review:")
if st.button("Predict"):
st.write("Knopka")
prediction = predict_sentiment(text_input)
st.write("prediction")
st.write("Predicted Sentiment:", prediction)