Spaces:
Runtime error
Runtime error
Oliver Li commited on
Commit ·
15103fe
1
Parent(s): 393a4bc
added label explanation
Browse files
app.py
CHANGED
|
@@ -16,15 +16,26 @@ st.write("Enter a text and select a pre-trained model to get the sentiment analy
|
|
| 16 |
text = st.text_input("Enter your text:")
|
| 17 |
|
| 18 |
# Model selection
|
| 19 |
-
model_options =
|
| 20 |
-
"distilbert-base-uncased-finetuned-sst-2-english"
|
| 21 |
-
|
| 22 |
-
|
| 23 |
-
|
| 24 |
-
|
| 25 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 26 |
selected_model = st.selectbox("Choose a pre-trained model:", model_options)
|
| 27 |
|
|
|
|
|
|
|
|
|
|
|
|
|
| 28 |
# Load the model and perform sentiment analysis
|
| 29 |
if st.button("Analyze"):
|
| 30 |
if not text:
|
|
@@ -36,7 +47,7 @@ if st.button("Analyze"):
|
|
| 36 |
st.write(f"Sentiment: {result[0]['label']} (confidence: {result[0]['score']:.2f})")
|
| 37 |
if result[0]['label'] == 'POSITIVE':
|
| 38 |
st.balloons()
|
| 39 |
-
elif result[0]['label']
|
| 40 |
st.error("Hater detected.")
|
| 41 |
else:
|
| 42 |
st.write("Enter a text and click 'Analyze' to perform sentiment analysis.")
|
|
|
|
| 16 |
text = st.text_input("Enter your text:")
|
| 17 |
|
| 18 |
# Model selection
|
| 19 |
+
model_options = {
|
| 20 |
+
"distilbert-base-uncased-finetuned-sst-2-english": {
|
| 21 |
+
"labels": ["NEGATIVE", "POSITIVE"],
|
| 22 |
+
"description": "This model classifies text into positive or negative sentiment. It is based on DistilBERT and fine-tuned on the Stanford Sentiment Treebank (SST-2) dataset.",
|
| 23 |
+
},
|
| 24 |
+
"textattack/bert-base-uncased-SST-2": {
|
| 25 |
+
"labels": ["LABEL_0", "LABEL_1"],
|
| 26 |
+
"description": "This model classifies text into positive(LABEL_1) or negative(LABEL_0) sentiment. It is based on BERT and fine-tuned on the Stanford Sentiment Treebank (SST-2) dataset.",
|
| 27 |
+
},
|
| 28 |
+
"cardiffnlp/twitter-roberta-base-sentiment": {
|
| 29 |
+
"labels": ["LABEL_0", "LABEL_1", "LABEL_2"],
|
| 30 |
+
"description": "This model classifies tweets into negative (LABEL_0), neutral(LABEL_1), or positive(LABEL_2) sentiment. It is based on RoBERTa and fine-tuned on a large dataset of tweets.",
|
| 31 |
+
},
|
| 32 |
+
}
|
| 33 |
selected_model = st.selectbox("Choose a pre-trained model:", model_options)
|
| 34 |
|
| 35 |
+
st.write("### Model Information")
|
| 36 |
+
st.write(f"**Labels:** {', '.join(model_options[selected_model]['labels'])}")
|
| 37 |
+
st.write(f"**Description:** {model_options[selected_model]['description']}")
|
| 38 |
+
|
| 39 |
# Load the model and perform sentiment analysis
|
| 40 |
if st.button("Analyze"):
|
| 41 |
if not text:
|
|
|
|
| 47 |
st.write(f"Sentiment: {result[0]['label']} (confidence: {result[0]['score']:.2f})")
|
| 48 |
if result[0]['label'] == 'POSITIVE':
|
| 49 |
st.balloons()
|
| 50 |
+
elif result[0]['label'] in ['NEGATIVE', 'LABEL_0'] and result[0]['score']> 0.9:
|
| 51 |
st.error("Hater detected.")
|
| 52 |
else:
|
| 53 |
st.write("Enter a text and click 'Analyze' to perform sentiment analysis.")
|