Spaces:
Sleeping
Sleeping
Upload app.py with huggingface_hub
Browse files
app.py
CHANGED
|
@@ -1,7 +1,9 @@
|
|
| 1 |
|
| 2 |
import streamlit as st
|
| 3 |
-
import
|
| 4 |
from huggingface_hub import snapshot_download
|
|
|
|
|
|
|
| 5 |
|
| 6 |
# Load the model and vectorizer from the repository
|
| 7 |
repo_id = "Makima57/sentiment-model-svc"
|
|
@@ -13,11 +15,12 @@ svc_model = joblib.load(f"{model_path}/svc_model.pkl")
|
|
| 13 |
# Load saved TfidfVectorizer
|
| 14 |
vectorizer = joblib.load(f"{model_path}/vectorizer.pkl")
|
| 15 |
|
| 16 |
-
#
|
| 17 |
-
def
|
| 18 |
text_vectorized = vectorizer.transform([text])
|
| 19 |
-
|
| 20 |
-
|
|
|
|
| 21 |
|
| 22 |
# Streamlit app
|
| 23 |
st.title('Sentiment Analysis App')
|
|
@@ -27,7 +30,13 @@ st.write('This app analyzes the sentiment of a given text using the SVC model.')
|
|
| 27 |
text = st.text_input('Enter a text to analyze sentiment')
|
| 28 |
|
| 29 |
if st.button('Analyze Sentiment'):
|
| 30 |
-
sentiment =
|
| 31 |
st.write('The sentiment of the text is:', sentiment)
|
| 32 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 33 |
|
|
|
|
| 1 |
|
| 2 |
import streamlit as st
|
| 3 |
+
import pandas as pd
|
| 4 |
from huggingface_hub import snapshot_download
|
| 5 |
+
import joblib
|
| 6 |
+
import numpy as np
|
| 7 |
|
| 8 |
# Load the model and vectorizer from the repository
|
| 9 |
repo_id = "Makima57/sentiment-model-svc"
|
|
|
|
| 15 |
# Load saved TfidfVectorizer
|
| 16 |
vectorizer = joblib.load(f"{model_path}/vectorizer.pkl")
|
| 17 |
|
| 18 |
+
# Function to analyze sentiment
|
| 19 |
+
def analyze_sentiment(text):
|
| 20 |
text_vectorized = vectorizer.transform([text])
|
| 21 |
+
text_dense = text_vectorized.toarray()
|
| 22 |
+
sentiment = svc_model.predict(text_dense)
|
| 23 |
+
return sentiment[0]
|
| 24 |
|
| 25 |
# Streamlit app
|
| 26 |
st.title('Sentiment Analysis App')
|
|
|
|
| 30 |
text = st.text_input('Enter a text to analyze sentiment')
|
| 31 |
|
| 32 |
if st.button('Analyze Sentiment'):
|
| 33 |
+
sentiment = analyze_sentiment(text)
|
| 34 |
st.write('The sentiment of the text is:', sentiment)
|
| 35 |
|
| 36 |
+
# Analyze sentiment of dataset
|
| 37 |
+
if st.button('Analyze Sentiment of Dataset'):
|
| 38 |
+
df = pd.read_csv('https://raw.githubusercontent.com/Sp1786/multiclass-sentiment-analysis-dataset/master/data/train.csv')
|
| 39 |
+
df['sentiment'] = df['text'].apply(analyze_sentiment)
|
| 40 |
+
st.write(df)
|
| 41 |
+
|
| 42 |
|