File size: 746 Bytes
4fe4948
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
import streamlit as st
from transformers import pipeline

# Load the sentiment analysis model from Hugging Face
classifier = pipeline("sentiment-analysis")

def predict_sentiment(text):
    result = classifier(text)
    return result[0]['label'], result[0]['score']

def main():
    st.title("Text Classification App")

    # User input
    text_input = st.text_area("Enter text:", "Type your text here.")

    # Prediction
    if st.button("Predict"):
        if text_input:
            sentiment, confidence = predict_sentiment(text_input)
            st.write(f"Sentiment: {sentiment}")
            st.write(f"Confidence: {confidence:.4f}")
        else:
            st.warning("Please enter some text.")

if __name__ == "__main__":
    main()