File size: 1,083 Bytes
41c9c41
 
 
 
 
 
 
 
 
 
 
 
 
dac9003
41c9c41
 
 
 
 
 
 
dac9003
41c9c41
 
dac9003
41c9c41
 
dac9003
41c9c41
 
 
 
 
 
 
 
 
 
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
32
33
34
35
36
37
38
# import streamlit as st
# from transformers import pipeline

# sentiment_analysis = pipeline("sentiment-analysis")

# text = st.text_input("Enter some text")

# if text:
#     result = sentiment_analysis(text)
#     st.json(result)



import streamlit as st
from transformers import pipeline, AutoModelForSequenceClassification, AutoTokenizer

# Load sentiment analysis model from Hugging Face
model_name = "distilbert-base-uncased-finetuned-sst-2-english"
model = AutoModelForSequenceClassification.from_pretrained(model_name)
tokenizer = AutoTokenizer.from_pretrained(model_name)
sentiment_analyzer = pipeline("sentiment-analysis", model=model, tokenizer=tokenizer)

# Streamlit UI
st.title("Sentiment Analysis App")

# User input
user_input = st.text_input("Enter a sentence:")

if user_input:
    # Perform sentiment analysis
    results = sentiment_analyzer(user_input)
    
    # Display sentiment and confidence
    sentiment = results[0]['label']
    confidence = results[0]['score']
    
    st.write(f"Sentiment: {sentiment}")
    st.write(f"Confidence: {confidence:.2f}")