txt-class / src /streamlit_app.py
a7madmostafa's picture
Update src/streamlit_app.py
71e24c6 verified
Raw
History Blame Contribute Delete
644 Bytes
import streamlit as st
from transformers import pipeline
# Load pipeline
@st.cache_resource
def load_pipeline():
return pipeline("text-classification", model="distilbert/distilbert-base-uncased-finetuned-sst-2-english")
pipe = load_pipeline()
# Streamlit UI
st.title("Sentiment Analysis with DistilBERT")
text = st.text_area("Enter text to analyze sentiment:", height=150)
if st.button("Analyze"):
if text.strip():
result = pipe(text)[0]
label = result['label']
score = round(result['score'], 4)
st.success(f"**Sentiment:** {label} ({score})")
else:
st.warning("Please enter some text.")