Spaces:
Sleeping
Sleeping
import streamlit as st | |
from transformers import pipeline | |
print("Loading the model...") | |
# Title and Description | |
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! | |
""") | |
# Initialize Hugging Face Sentiment Analysis Pipeline | |
def load_model(): | |
print("before load model") | |
return pipeline("sentiment-analysis", model="distilbert-base-uncased-finetuned-sst-2-english") | |
sentiment_analyzer = load_model() | |
# Input Text from User | |
user_input = st.text_area("Enter some text to analyze:", "Streamlit and Hugging Face make NLP fun!") | |
# Analyze Sentiment | |
if st.button("Analyze Sentiment"): | |
print("button click") | |
if user_input.strip(): | |
result = sentiment_analyzer(user_input)[0] | |
sentiment = result['label'] | |
score = result['score'] | |
# Display the Result | |
st.subheader("Sentiment Analysis Result") | |
st.write(f"**Sentiment:** {sentiment}") | |
st.write(f"**Confidence Score:** {score:.2f}") | |
else: | |
st.warning("Please enter some text to analyze!") | |
# Sidebar with About Information | |
st.sidebar.title("About") | |
st.sidebar.info(""" | |
This app demonstrates the use of Hugging Face's NLP models with Streamlit. | |
It uses the `distilbert-base-uncased-finetuned-sst-2-english` model for sentiment analysis. | |
""") | |
print("after") | |