Spaces:
Build error
Build error
Update app.py
Browse files
app.py
CHANGED
|
@@ -9,13 +9,13 @@ from sklearn.pipeline import make_pipeline
|
|
| 9 |
# Load multi-class sentiment analysis model
|
| 10 |
sentiment_model = pipeline("text-classification", model="cardiffnlp/twitter-roberta-base-sentiment", top_k=None)
|
| 11 |
|
| 12 |
-
# Define possible sentiment classes
|
| 13 |
label_mapping = {
|
| 14 |
-
"LABEL_0": "
|
| 15 |
-
"LABEL_1": "
|
| 16 |
-
"LABEL_2": "
|
| 17 |
-
"LABEL_3": "
|
| 18 |
-
"LABEL_4": "
|
| 19 |
}
|
| 20 |
|
| 21 |
# Function to get sentiment prediction
|
|
@@ -28,7 +28,7 @@ def analyze_sentiment(text):
|
|
| 28 |
|
| 29 |
# Suggest test cases to ensure correct labeling
|
| 30 |
def get_suggestions():
|
| 31 |
-
return "Try these examples:\n- 'I love this! Best experience ever!' (
|
| 32 |
|
| 33 |
# Explainability function using LIME
|
| 34 |
def explain_prediction(text):
|
|
@@ -47,15 +47,65 @@ iface = gr.Interface(
|
|
| 47 |
inputs="text",
|
| 48 |
outputs="text",
|
| 49 |
title="Multi-Class Sentiment Analysis App",
|
| 50 |
-
description="Enter a sentence to analyze its sentiment across multiple categories.",
|
| 51 |
live=True,
|
| 52 |
examples=[
|
| 53 |
["I love this! Best experience ever!"],
|
| 54 |
["I am so happy today!"],
|
| 55 |
["It was okay, nothing special."],
|
| 56 |
["I am disappointed with this product."],
|
| 57 |
-
["This is the worst day of my life."]
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 58 |
]
|
| 59 |
)
|
| 60 |
|
| 61 |
-
iface.launch()
|
|
|
|
| 9 |
# Load multi-class sentiment analysis model
|
| 10 |
sentiment_model = pipeline("text-classification", model="cardiffnlp/twitter-roberta-base-sentiment", top_k=None)
|
| 11 |
|
| 12 |
+
# Define possible sentiment classes with a reduced, logical set
|
| 13 |
label_mapping = {
|
| 14 |
+
"LABEL_0": "negative",
|
| 15 |
+
"LABEL_1": "neutral",
|
| 16 |
+
"LABEL_2": "positive",
|
| 17 |
+
"LABEL_3": "anger",
|
| 18 |
+
"LABEL_4": "chill"
|
| 19 |
}
|
| 20 |
|
| 21 |
# Function to get sentiment prediction
|
|
|
|
| 28 |
|
| 29 |
# Suggest test cases to ensure correct labeling
|
| 30 |
def get_suggestions():
|
| 31 |
+
return "Try these examples:\n- 'I love this! Best experience ever!' (positive)\n- 'I am so happy today!' (positive)\n- 'It was okay, nothing special.' (neutral)\n- 'I am disappointed with this product.' (negative)\n- 'This is the worst day of my life.' (negative)\n- 'I am furious right now!' (anger)\n- 'I am extremely relaxed and enjoying the moment.' (chill)"
|
| 32 |
|
| 33 |
# Explainability function using LIME
|
| 34 |
def explain_prediction(text):
|
|
|
|
| 47 |
inputs="text",
|
| 48 |
outputs="text",
|
| 49 |
title="Multi-Class Sentiment Analysis App",
|
| 50 |
+
description="Enter a sentence to analyze its sentiment across multiple categories (Negative, Neutral, Positive, Anger, Chill).",
|
| 51 |
live=True,
|
| 52 |
examples=[
|
| 53 |
["I love this! Best experience ever!"],
|
| 54 |
["I am so happy today!"],
|
| 55 |
["It was okay, nothing special."],
|
| 56 |
["I am disappointed with this product."],
|
| 57 |
+
["This is the worst day of my life."],
|
| 58 |
+
["The movie was fantastic, I really enjoyed it!"],
|
| 59 |
+
["I am so angry, I can't believe this happened!"],
|
| 60 |
+
["I feel completely at peace right now."],
|
| 61 |
+
["The service was terrible, I wouldn’t recommend this place."],
|
| 62 |
+
["I feel great today, everything is going well!"],
|
| 63 |
+
["It’s just another day, nothing special to report."],
|
| 64 |
+
["This food is awful, I can’t even eat it!"],
|
| 65 |
+
["The book was so engaging, I couldn’t put it down!"],
|
| 66 |
+
["I don’t really have an opinion on this matter."],
|
| 67 |
+
["My day has been okay, not good but not bad either."],
|
| 68 |
+
["I regret buying this product, it’s a waste of money."],
|
| 69 |
+
["The customer support was helpful and solved my issue quickly."],
|
| 70 |
+
["This experience has been quite frustrating, honestly."],
|
| 71 |
+
["I had fun at the party, it was a great time!"],
|
| 72 |
+
["There was too much traffic today, it was so annoying."],
|
| 73 |
+
["I appreciate your help, it really made a difference."],
|
| 74 |
+
["The test was hard, but I think I did okay."],
|
| 75 |
+
["I wouldn’t buy this again, it didn’t meet my expectations."],
|
| 76 |
+
["This new update has improved the app significantly!"],
|
| 77 |
+
["I’m not sure how I feel about this decision."],
|
| 78 |
+
["Everything went smoothly today, no issues at all."],
|
| 79 |
+
["The weather is nice today, not too hot or too cold."],
|
| 80 |
+
["I had a terrible time at the event, it was poorly organized."],
|
| 81 |
+
["My experience was neutral, I don’t have strong feelings either way."],
|
| 82 |
+
["I highly recommend this to everyone, it’s fantastic!"],
|
| 83 |
+
["This place is so relaxing, I could stay here forever."],
|
| 84 |
+
["I had a bad day, but I’ll get through it."],
|
| 85 |
+
["The lecture was informative, I learned a lot."],
|
| 86 |
+
["It’s neither good nor bad, just okay overall."],
|
| 87 |
+
["The store was crowded and the staff was rude, not a good experience."],
|
| 88 |
+
["I’m satisfied with my purchase, it met my expectations."],
|
| 89 |
+
["This situation is frustrating, I don’t know what to do."],
|
| 90 |
+
["I’m feeling optimistic about the future!"],
|
| 91 |
+
["It was a boring day, nothing interesting happened."],
|
| 92 |
+
["I love spending time with my friends, they make me happy."],
|
| 93 |
+
["The flight was delayed, but at least I got home safely."],
|
| 94 |
+
["This dessert is absolutely delicious, I need more!"],
|
| 95 |
+
["I wish things had gone differently, but it’s okay."],
|
| 96 |
+
["The staff was unfriendly, I didn’t feel welcome at all."],
|
| 97 |
+
["I had a productive day, I got a lot of work done."],
|
| 98 |
+
["This movie was neither exciting nor dull, just in between."],
|
| 99 |
+
["I’m really grateful for your kindness, it means a lot."],
|
| 100 |
+
["I have no strong opinion about this, it’s just okay."],
|
| 101 |
+
["The food was decent, but I’ve had better."],
|
| 102 |
+
["Everything was perfect, I couldn’t have asked for more!"],
|
| 103 |
+
["The trip was stressful, nothing went according to plan."],
|
| 104 |
+
["I’m hopeful that things will get better soon."],
|
| 105 |
+
["The presentation was well done, I was impressed."],
|
| 106 |
+
["I feel indifferent about this, it doesn’t affect me much."],
|
| 107 |
+
["The concert was amazing, I had a blast!"]
|
| 108 |
]
|
| 109 |
)
|
| 110 |
|
| 111 |
+
iface.launch()
|