shayankhan7's picture
Update app.py
ed55257 verified
raw
history blame
737 Bytes
import streamlit as st
from transformers import pipeline
# Load sentiment-analysis pipeline from Hugging Face
@st.cache_resource
def load_model():
return pipeline("sentiment-analysis")
sentiment_pipeline = load_model()
# Streamlit UI
st.title("Smart Sentiment Analyzer 🤖")
st.markdown("Analyze your sentence using a real AI model (DistilBERT).")
text = st.text_area("Enter your sentence:")
if st.button("Analyze Sentiment"):
if text.strip() == "":
st.warning("Please enter some text.")
else:
result = sentiment_pipeline(text)[0]
label = result["label"]
score = round(result["score"] * 100, 2)
st.success(f"**Sentiment:** {label}")
st.info(f"**Confidence:** {score}%")