sentiment / app.py
mim981's picture
Create app.py
f339f2c verified
raw
history blame contribute delete
651 Bytes
import streamlit as st
from transformers import pipeline
# Load a pretrained sentiment-analysis model from Hugging Face
@st.cache_resource
def load_model():
return pipeline("sentiment-analysis")
model = load_model()
# Streamlit UI
st.title("🧠 Sentiment Analysis App")
st.write("Type a sentence and find out if it’s Positive or Negative!")
user_input = st.text_area("Enter your text here 👇")
if st.button("Analyze Sentiment"):
if user_input.strip():
result = model(user_input)[0]
st.success(f"**Label:** {result['label']} | **Score:** {result['score']:.2f}")
else:
st.warning("Please enter some text!")