khadija3818's picture
Create app.py
f4f0513
raw
history blame contribute delete
856 Bytes
import streamlit as st
from transformers import pipeline
# Load the sentiment analysis model from Hugging Face
sentiment_analysis = pipeline("sentiment-analysis")
# Function to get sentiment prediction
def predict_sentiment(text):
result = sentiment_analysis(text)
label = result[0]['label']
score = result[0]['score']
return label, score
# Streamlit web app
def main():
st.title("Sentiment Analysis App")
# Input text area
user_input = st.text_area("Enter text:", "Type or paste your text here...")
# Button to trigger sentiment prediction
if st.button("Predict Sentiment"):
# Display the result
sentiment_label, sentiment_score = predict_sentiment(user_input)
st.write(f"Sentiment: {sentiment_label}, Score: {sentiment_score:.4f}")
# Run the app
if __name__ == "__main__":
main()