Spaces:
Sleeping
Delete app.py
Browse filesimport streamlit as st
import pandas as pd
import plotly.express as px
from transformers import pipeline
def main():
st.set_page_config(page_title="Sentiment Analysis App")
st.sidebar.title("Sentiment Analysis App")
st.sidebar.write("Choose a pre-trained model for sentiment analysis")
model_name = st.sidebar.selectbox("Select Model", ["bert-base-uncased", "distilbert-base-uncased", "roberta-base"])
text_input = st.text_input("Enter text for sentiment analysis")
if st.button("Analyze"):
if text_input:
sentiment_classifier = pipeline("sentiment-analysis", model=model_name)
result = sentiment_classifier(text_input)[0]
st.write(f"Sentiment: {result['label']}")
st.write(f"Score: {round(result['score'], 4)}")
# create a dataframe to hold the sentiment distribution
df_sentiments = pd.DataFrame({"sentiment": ["Positive", "Negative", "Neutral"], "count": [0, 0, 0]})
# get the sentiment distribution of the text using the selected model
results = sentiment_classifier(text_input, task="sentiment-analysis")
for r in results:
if r["label"] == "POSITIVE":
df_sentiments.loc[0, "count"] = r["score"]
elif r["label"] == "NEGATIVE":
df_sentiments.loc[1, "count"] = r["score"]
elif r["label"] == "NEUTRAL":
df_sentiments.loc[2, "count"] = r["score"]
# plot the sentiment distribution as a pie chart
fig = px.pie(df_sentiments, values='count', names='sentiment', hole=.4)
st.plotly_chart(fig)
else:
st.warning("Please enter some text for sentiment analysis")
if __name__ == "__main__":
main()
@@ -1,22 +0,0 @@
|
|
1 |
-
import streamlit as st
|
2 |
-
import pandas as pd
|
3 |
-
from transformers import pipeline
|
4 |
-
|
5 |
-
def main():
|
6 |
-
st.set_page_config(page_title="Sentiment Analysis App")
|
7 |
-
st.sidebar.title("Sentiment Analysis App")
|
8 |
-
st.sidebar.write("Choose a pre-trained model for sentiment analysis")
|
9 |
-
model_name = st.sidebar.selectbox("Select Model", ["bert-base-uncased", "distilbert-base-uncased", "roberta-base"])
|
10 |
-
text_input = st.text_input("Enter text for sentiment analysis")
|
11 |
-
|
12 |
-
if st.button("Analyze"):
|
13 |
-
if text_input:
|
14 |
-
sentiment_classifier = pipeline("sentiment-analysis", model=model_name)
|
15 |
-
result = sentiment_classifier(text_input)[0]
|
16 |
-
st.write(f"Sentiment: {result['label']}")
|
17 |
-
st.write(f"Score: {round(result['score'], 4)}")
|
18 |
-
else:
|
19 |
-
st.warning("Please enter some text for sentiment analysis")
|
20 |
-
|
21 |
-
if __name__ == "__main__":
|
22 |
-
main()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|