|
import streamlit as st |
|
from transformers import pipeline |
|
|
|
print("Loading the model...") |
|
|
|
|
|
|
|
st.title("Sentiment Analysis Web App") |
|
|
|
st.write(""" |
|
### Powered by Hugging Face and Streamlit |
|
This app uses a pre-trained NLP model from Hugging Face to analyze the sentiment of the text you enter. |
|
Try entering a sentence to see if it's positive, negative, or neutral! |
|
""") |
|
|
|
@st.cache_resource |
|
def load_model(): |
|
print("before load model") |
|
return pipeline("sentiment-analysis", model="distilbert-base-uncased-finetuned-sst-2-english") |
|
sentiment_analyzer = load_model() |
|
|
|
user_input = st.text_area("Enter some text to analyze:", "Streamlit and Hugging Face make NLP fun!") |
|
|
|
if st.button("Analyze Sentiment"): |
|
print("button click") |
|
if user_input.strip(): |
|
result = sentiment_analyzer(user_input) [0] |
|
sentiment result["label"] |
|
score = result['score'] |
|
|