File size: 1,105 Bytes
591ce15
b1ed35e
591ce15
b1ed35e
 
ab96cce
591ce15
4106091
591ce15
 
 
 
 
 
4106091
 
591ce15
b1ed35e
 
4e7932e
b1ed35e
 
ab96cce
 
 
 
 
 
4e7932e
 
 
 
 
 
 
 
 
b1ed35e
4e7932e
4106091
591ce15
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

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)