sentimentSVC / app.py
Makima57's picture
Upload app.py with huggingface_hub
ab96cce verified
import pandas as pd
from huggingface_hub import snapshot_download
import joblib
import numpy as np
import streamlit as st
# Load the model and vectorizer from the repository
repo_id = "Makima57/sentiment-model-svc"
model_path = snapshot_download(repo_id=repo_id)
# Load saved SVC model
svc_model = joblib.load(f"{model_path}/svc_model.pkl")
# Load saved TfidfVectorizer
vectorizer = joblib.load(f"{model_path}/vectorizer.pkl")
# Function to analyze sentiment
def analyze_sentiment(text):
text_vectorized = vectorizer.transform([text])
text_dense = text_vectorized.toarray()
sentiment = svc_model.predict(text_dense)
if sentiment[0] == 0:
return "Negative"
elif sentiment[0] == 1:
return "Neutral"
else:
return "Positive"
# Streamlit app
st.title('Sentiment Analysis App')
st.write('This app analyzes the sentiment of a given text using the SVC model.')
text = st.text_input('Enter a text to analyze sentiment')
if st.button('Analyze Sentiment'):
sentiment = analyze_sentiment(text)
st.write('The sentiment of the text is:', sentiment)