dog / app.py
balnur
main
526b8c5
raw
history blame
996 Bytes
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']