Spaces:
Runtime error
Runtime error
HarshaBattula
commited on
Commit
Β·
e88d283
1
Parent(s):
5fd634a
updated colors
Browse files
app.py
CHANGED
@@ -3,6 +3,31 @@ from pyabsa import ATEPCCheckpointManager
|
|
3 |
import gradio as gr
|
4 |
|
5 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
6 |
|
7 |
def annotate_sentiment(tokens, aspect_positions, sentiment_list):
|
8 |
"""
|
@@ -19,7 +44,7 @@ def annotate_sentiment(tokens, aspect_positions, sentiment_list):
|
|
19 |
for i, token_group in enumerate(tokens):
|
20 |
if aspect_index < len(aspect_positions) and i == aspect_positions[aspect_index]:
|
21 |
for token in token_group:
|
22 |
-
sentiment =
|
23 |
annotated_tokens.append((token, sentiment))
|
24 |
aspect_index += 1
|
25 |
else:
|
@@ -52,10 +77,10 @@ def annotate_text_sentiment(text):
|
|
52 |
aspect_positions = [position[0]-1 for position in aspect_extraction_result['position']]
|
53 |
sentiment_list = aspect_extraction_result["sentiment"]
|
54 |
|
|
|
55 |
annotated_tokens = annotate_sentiment(tokens, aspect_positions, sentiment_list)
|
56 |
return annotated_tokens
|
57 |
|
58 |
-
|
59 |
# Initializing the aspect extractor model
|
60 |
checkpoint_map = available_checkpoints()
|
61 |
aspect_extractor = ATEPCCheckpointManager.get_aspect_extractor(checkpoint='english',
|
@@ -77,7 +102,7 @@ demo1 = gr.Interface(
|
|
77 |
label="Aspect Detector based on DeBERTa",
|
78 |
combine_adjacent=True,
|
79 |
show_legend=True,
|
80 |
-
).style(color_map={"
|
81 |
theme=gr.themes.Base()
|
82 |
)
|
83 |
|
@@ -95,7 +120,7 @@ demo2 = gr.Interface(
|
|
95 |
label="Aspect Detector based on Relational Graph Attention Networks, and BERT",
|
96 |
combine_adjacent=True,
|
97 |
show_legend=True,
|
98 |
-
).style(color_map={"
|
99 |
theme=gr.themes.Base()
|
100 |
)
|
101 |
|
|
|
3 |
import gradio as gr
|
4 |
|
5 |
|
6 |
+
def assign_sentiment_marker(sentiment_list, aspect_index):
|
7 |
+
"""
|
8 |
+
This function returns a sentiment marker '+' for Positive, '-' for Negative, and '$' for any other sentiment.
|
9 |
+
It maps the sentiment from the sentiment_list at the aspect_index to the respective marker.
|
10 |
+
|
11 |
+
Parameters:
|
12 |
+
sentiment_list (list): A list of sentiments.
|
13 |
+
aspect_index (int): The index of the sentiment in sentiment_list to map to a marker.
|
14 |
+
|
15 |
+
Returns:
|
16 |
+
str: The sentiment marker.
|
17 |
+
"""
|
18 |
+
|
19 |
+
# Define a dictionary to map sentiment labels to markers.
|
20 |
+
sentiment_markers = {
|
21 |
+
"Positive": "pos",
|
22 |
+
"Negative": "neg"
|
23 |
+
}
|
24 |
+
|
25 |
+
# Fetch sentiment label from the sentiment_list using aspect_index.
|
26 |
+
sentiment_label = sentiment_list[aspect_index]
|
27 |
+
|
28 |
+
# Use get method on dictionary to fetch corresponding marker or default to '$' for unlisted sentiments.
|
29 |
+
return sentiment_markers.get(sentiment_label, "neu")
|
30 |
+
|
31 |
|
32 |
def annotate_sentiment(tokens, aspect_positions, sentiment_list):
|
33 |
"""
|
|
|
44 |
for i, token_group in enumerate(tokens):
|
45 |
if aspect_index < len(aspect_positions) and i == aspect_positions[aspect_index]:
|
46 |
for token in token_group:
|
47 |
+
sentiment = assign_sentiment_marker(sentiment_list, aspect_index)
|
48 |
annotated_tokens.append((token, sentiment))
|
49 |
aspect_index += 1
|
50 |
else:
|
|
|
77 |
aspect_positions = [position[0]-1 for position in aspect_extraction_result['position']]
|
78 |
sentiment_list = aspect_extraction_result["sentiment"]
|
79 |
|
80 |
+
print(sentiment_list)
|
81 |
annotated_tokens = annotate_sentiment(tokens, aspect_positions, sentiment_list)
|
82 |
return annotated_tokens
|
83 |
|
|
|
84 |
# Initializing the aspect extractor model
|
85 |
checkpoint_map = available_checkpoints()
|
86 |
aspect_extractor = ATEPCCheckpointManager.get_aspect_extractor(checkpoint='english',
|
|
|
102 |
label="Aspect Detector based on DeBERTa",
|
103 |
combine_adjacent=True,
|
104 |
show_legend=True,
|
105 |
+
).style(color_map={"pos": "green", "neg": "red", "neu":"blue"}),
|
106 |
theme=gr.themes.Base()
|
107 |
)
|
108 |
|
|
|
120 |
label="Aspect Detector based on Relational Graph Attention Networks, and BERT",
|
121 |
combine_adjacent=True,
|
122 |
show_legend=True,
|
123 |
+
).style(color_map={"pos": "green", "neg": "red", "neu":"blue"}),
|
124 |
theme=gr.themes.Base()
|
125 |
)
|
126 |
|