File size: 775 Bytes
2fcc45c
31a082a
 
2fcc45c
 
31a082a
2fcc45c
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
31a082a
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 pipeline
sentiment_pipeline = pipeline("sentiment-analysis")

# Streamlit interface
st.title("Sentiment Analysis with Hugging Face Transformers")

# Input text box
user_input = st.text_area("Enter text to analyze sentiment:", "I love using Hugging Face transformers!")

# Analyze sentiment button
if st.button("Analyze Sentiment"):
    # Perform sentiment analysis
    result = sentiment_pipeline(user_input)
    
    # Display the result
    sentiment = result[0]['label']
    confidence = result[0]['score']
    st.write(f"Sentiment: **{sentiment}**")
    st.write(f"Confidence: **{confidence:.4f}**")

# To run the Streamlit app, use the command:
# streamlit run your_script_name.py