File size: 996 Bytes
8d6a14b 526b8c5 8d6a14b 526b8c5 f897d1b 526b8c5 f897d1b 526b8c5 |
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 |
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
@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()
# 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']
|