File size: 931 Bytes
54cebbd
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
28
29
30
31
import streamlit as st
from transformers import pipeline

# Load the sentiment classifier model
distilled_student_sentiment_classifier = pipeline(
    model="lxyuan/distilbert-base-multilingual-cased-sentiments-student",
    return_all_scores=True
)

# Define the Streamlit app
def main():
    # Add a title to the app
    st.title("DistilBERT Sentiment Analysis")

    # Add a text input field for user input
    user_input = st.text_input("Enter text:")

    # Perform sentiment analysis when the user submits input
    if st.button("Analyze"):
        # Perform sentiment analysis on the input text
        result = distilled_student_sentiment_classifier(user_input)

        # Display the sentiment analysis results
        st.write("Sentiment Analysis Results:")
        for item in result:
            st.write(f"Label: {item['label']}, Score: {item['score']}")

# Run the Streamlit app
if __name__ == "__main__":
    main()