File size: 726 Bytes
6af6114
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
import streamlit as st
from transformers import pipeline

# Title and description
st.title("Sentiment Analysis")
st.write("This application performs text classification using a pre-trained Hugging Face model.")

# Define the model and pipeline
model_name = "distilbert-base-uncased-finetuned-sst-2-english"
classifier = pipeline("sentiment-analysis", model=model_name)

# Get user input
user_input = st.text_area("Enter text:", placeholder="Type your text here...")

# Analyze and display results
if st.button("Analyze"):
    if user_input.strip():
        result = classifier(user_input)
        st.write(f"**Result:** {result[0]['label']} ({result[0]['score']:.2f})")
    else:
        st.warning("Please enter some text.")