Spaces:
Build error
Build error
Delete app.py
Browse files
app.py
DELETED
|
@@ -1,71 +0,0 @@
|
|
| 1 |
-
import streamlit as st
|
| 2 |
-
import joblib
|
| 3 |
-
import re
|
| 4 |
-
import nltk
|
| 5 |
-
from nltk.corpus import stopwords
|
| 6 |
-
from sklearn.feature_extraction.text import TfidfVectorizer
|
| 7 |
-
|
| 8 |
-
nltk.download('stopwords')
|
| 9 |
-
stop_words = set(stopwords.words('english'))
|
| 10 |
-
|
| 11 |
-
# LOAD MODEL AND VECTORIZER
|
| 12 |
-
with open("sentimentAnalysis_model.pkl", "rb") as model_file:
|
| 13 |
-
model = joblib.load(model_file)
|
| 14 |
-
with open("vectorizer.pkl", "rb") as vectorizer_file:
|
| 15 |
-
vectorizer = joblib.load(vectorizer_file)
|
| 16 |
-
|
| 17 |
-
|
| 18 |
-
app, model_eval = st.tabs(["Application", "Model Evaluation"])
|
| 19 |
-
# STREAMLIT APP TAB 1
|
| 20 |
-
with app:
|
| 21 |
-
# MAPPING RESULTS
|
| 22 |
-
sentiment_mapping = {0: "Neutral", 1: "Positive", 2: "Negative"}
|
| 23 |
-
|
| 24 |
-
# FUNCTION TO REDUCE TEXT TO ITS MOST BASIC FORM
|
| 25 |
-
def clean_text(text):
|
| 26 |
-
text = text.lower()
|
| 27 |
-
text = re.sub(r'[^a-zA-Z\s]', '', text)
|
| 28 |
-
text = ' '.join([word for word in text.split() if word not in stop_words])
|
| 29 |
-
return text
|
| 30 |
-
|
| 31 |
-
# STREAMLIT UI
|
| 32 |
-
st.title("Sentiment Analysis App")
|
| 33 |
-
st.write("Enter text below to analyze its sentiment.")
|
| 34 |
-
|
| 35 |
-
user_input = st.text_area("Enter text:")
|
| 36 |
-
|
| 37 |
-
if st.button("Analyze Sentiment"):
|
| 38 |
-
if user_input:
|
| 39 |
-
cleaned_input = clean_text(user_input)
|
| 40 |
-
transformed_input = vectorizer.transform([cleaned_input])
|
| 41 |
-
|
| 42 |
-
prediction = model.predict(transformed_input)[0]
|
| 43 |
-
sentiment = sentiment_mapping[prediction]
|
| 44 |
-
|
| 45 |
-
st.write(f"Predicted Sentiment: **{sentiment}**")
|
| 46 |
-
else:
|
| 47 |
-
st.write("Please enter some text to analyze.")
|
| 48 |
-
|
| 49 |
-
with model_eval:
|
| 50 |
-
|
| 51 |
-
st.header("Model Evaluation")
|
| 52 |
-
st.write("The Sentiment Analysis model was trained in order to detect if a text is positive, negative, or neutral. The dataset was taken from kaggle.")
|
| 53 |
-
st.write("dataset by Dataset by Ismiel Hossen Abir. Link: https://www.kaggle.com/datasets/mdismielhossenabir/sentiment-analysis")
|
| 54 |
-
|
| 55 |
-
# SENTIMENT DISTRIBUTION
|
| 56 |
-
st.header("Sentiment Distribution")
|
| 57 |
-
st.write("The model was trained using a dataset with the total amount of text equivalent to the following labels")
|
| 58 |
-
st.image("sentiment_distribution.png")
|
| 59 |
-
|
| 60 |
-
# CONFUSION MATRIX
|
| 61 |
-
st.title("Confusion Matrix")
|
| 62 |
-
st.write("The confusion matrix displays the actual values or true labels with the predicted values from the model. With this, we can identify the margin of error the model has.")
|
| 63 |
-
st.image("confusion_matrix.png")
|
| 64 |
-
|
| 65 |
-
# EVALUATION MATRICS
|
| 66 |
-
st.title("Evaluation Metrics")
|
| 67 |
-
st.write("The image below represents the Accuracy, F1 score and the classification report of the model")
|
| 68 |
-
st.image("classification_report.png")
|
| 69 |
-
st.write("The model can be improved by using other algorithms, but logistic regression was used for project purposes")
|
| 70 |
-
|
| 71 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|