Sentiment_analysis_app / sentiment_huggingface.py
FrancescoConte's picture
removed the training from the web app
ddc2737
# Imports
import numpy as np
from transformers import pipeline
import streamlit as st
import torch
# Detect device automatically
device = 0 if torch.cuda.is_available() else -1
tokenizer_model="distilbert-base-uncased-finetuned-sst-2-english"
dataset="imdb"
seed = 42
### Load the model -------------------------------
print(f"Using {tokenizer_model} model previously trained on dataset {dataset}")
model_name = "FrancescoConte/FC_finetuning-sentiment-model-3000-samples"
# Define the final sentiment analysis model
sentiment_model = pipeline(model=model_name, task="sentiment-analysis")
### Use the model --------------------
#try_text=["I love this move", "This movie sucks!"]
#print(sentiment_model(try_text))
### Put it on streamlit -------------------
st.title("Sentiment Analysis App")
text = st.text_area("Enter text for sentiment analysis:")
if st.button("Analyze"):
with st.spinner("Running inference..."):
result = sentiment_model(text)[0]
st.success(f"**Label:** {result['label']}\n\n**Confidence:** {result['score']:.5f}")