-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsentiment_analysis_app.py
41 lines (34 loc) · 1.07 KB
/
sentiment_analysis_app.py
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
39
40
41
!pip install streamlit transformers pandas
import streamlit as st
import pandas as pd
from transformers import pipeline
# Load the sentiment analysis pipeline
sentiment_analyzer = pipeline("sentiment-analysis")
# Sample dataset (replace with your own data)
data = {
"text": [
"This is a very good product.",
"I am not happy with this service.",
"Neutral opinion.",
"Excellent! I love it.",
"This is terrible."
]
}
df = pd.DataFrame(data)
# Streamlit app
st.title("Sentiment Analysis Demo")
# User input
user_input = st.text_input("Enter text:")
# Analyze user input
if user_input:
result = sentiment_analyzer(user_input)[0]
st.write(f"**Sentiment:** {result['label']}")
st.write(f"**Score:** {result['score']:.2f}")
# Display sample data
st.header("Sample Data")
st.dataframe(df)
# Analyze sample data
if st.button("Analyze Sample Data"):
df['sentiment'] = df['text'].apply(lambda x: sentiment_analyzer(x)[0]['label'])
df['score'] = df['text'].apply(lambda x: sentiment_analyzer(x)[0]['score'])
st.dataframe(df)