Update app.py
Browse files
app.py
CHANGED
|
@@ -84,7 +84,6 @@ def get_sentiment_values(text: str):
|
|
| 84 |
sentiments = pipe(text)[0]
|
| 85 |
return {k:v for k,v in [(list(sentiment.values())[0], list(sentiment.values())[1]) for sentiment in sentiments]}
|
| 86 |
|
| 87 |
-
# Modify the predict_subjectivity function to return additional information
|
| 88 |
def analyze(text):
|
| 89 |
# Extract sentiment values
|
| 90 |
sentiment_values = get_sentiment_values(text)
|
|
@@ -120,12 +119,29 @@ def analyze(text):
|
|
| 120 |
# Calculate probabilities using softmax
|
| 121 |
prob_sentiment = torch.nn.functional.softmax(logits_sentiment, dim=1)[0]
|
| 122 |
|
| 123 |
-
#
|
| 124 |
-
|
| 125 |
-
|
| 126 |
-
|
| 127 |
-
|
| 128 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 129 |
|
| 130 |
# Update the Gradio interface
|
| 131 |
with gr.Blocks(theme=gr.themes.Soft(), css="""
|
|
|
|
| 84 |
sentiments = pipe(text)[0]
|
| 85 |
return {k:v for k,v in [(list(sentiment.values())[0], list(sentiment.values())[1]) for sentiment in sentiments]}
|
| 86 |
|
|
|
|
| 87 |
def analyze(text):
|
| 88 |
# Extract sentiment values
|
| 89 |
sentiment_values = get_sentiment_values(text)
|
|
|
|
| 119 |
# Calculate probabilities using softmax
|
| 120 |
prob_sentiment = torch.nn.functional.softmax(logits_sentiment, dim=1)[0]
|
| 121 |
|
| 122 |
+
# Prepare data for the BarPlot (numerical values)
|
| 123 |
+
chart_data = [
|
| 124 |
+
{"category": "Positive", "value": positive},
|
| 125 |
+
{"category": "Neutral", "value": neutral},
|
| 126 |
+
{"category": "Negative", "value": negative},
|
| 127 |
+
{"category": "Sent-Subj OBJ", "value": prob_sentiment[0].item()},
|
| 128 |
+
{"category": "Sent-Subj SUBJ", "value": prob_sentiment[1].item()},
|
| 129 |
+
{"category": "TextOnly OBJ", "value": prob_base[0].item()},
|
| 130 |
+
{"category": "TextOnly SUBJ", "value": prob_base[1].item()}
|
| 131 |
+
]
|
| 132 |
+
|
| 133 |
+
# Prepare data for the Dataframe (string values)
|
| 134 |
+
table_data = [
|
| 135 |
+
["Positive", f"{positive:.2%}"],
|
| 136 |
+
["Neutral", f"{neutral:.2%}"],
|
| 137 |
+
["Negative", f"{negative:.2%}"],
|
| 138 |
+
["Sent-Subj OBJ", f"{prob_sentiment[0]:.2%}"],
|
| 139 |
+
["Sent-Subj SUBJ", f"{prob_sentiment[1]:.2%}"],
|
| 140 |
+
["TextOnly OBJ", f"{prob_base[0]:.2%}"],
|
| 141 |
+
["TextOnly SUBJ", f"{prob_base[1]:.2%}"]
|
| 142 |
+
]
|
| 143 |
+
|
| 144 |
+
return chart_data, table_data
|
| 145 |
|
| 146 |
# Update the Gradio interface
|
| 147 |
with gr.Blocks(theme=gr.themes.Soft(), css="""
|