Update app.py
Browse fileschange to display tokens instead
app.py
CHANGED
|
@@ -155,16 +155,23 @@ def generate_charts(ner_output_bin: dict, ner_output_ext: dict) -> Tuple[go.Figu
|
|
| 155 |
|
| 156 |
return fig1, fig2, wordcloud_image
|
| 157 |
|
|
|
|
| 158 |
def generate_wordcloud(entities: List[Dict], color_map: Dict[str, str]) -> np.ndarray:
|
| 159 |
-
|
| 160 |
-
|
| 161 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 162 |
|
| 163 |
# Create a dictionary for word cloud
|
| 164 |
-
word_freq = {text: score for text, score in zip(
|
| 165 |
|
| 166 |
def color_func(word, font_size, position, orientation, random_state=None, **kwargs):
|
| 167 |
-
entity_type = next(
|
| 168 |
return color_map.get(entity_type, "#FFFFFF")
|
| 169 |
|
| 170 |
wordcloud = WordCloud(width=800, height=400, background_color='black', color_func=color_func).generate_from_frequencies(word_freq)
|
|
|
|
| 155 |
|
| 156 |
return fig1, fig2, wordcloud_image
|
| 157 |
|
| 158 |
+
|
| 159 |
def generate_wordcloud(entities: List[Dict], color_map: Dict[str, str]) -> np.ndarray:
|
| 160 |
+
token_texts = []
|
| 161 |
+
token_scores = []
|
| 162 |
+
token_types = []
|
| 163 |
+
|
| 164 |
+
for entity in entities:
|
| 165 |
+
for token in entity['tokens']:
|
| 166 |
+
token_texts.append(token)
|
| 167 |
+
token_scores.append(entity['score'])
|
| 168 |
+
token_types.append(entity['entity'])
|
| 169 |
|
| 170 |
# Create a dictionary for word cloud
|
| 171 |
+
word_freq = {text: score for text, score in zip(token_texts, token_scores)}
|
| 172 |
|
| 173 |
def color_func(word, font_size, position, orientation, random_state=None, **kwargs):
|
| 174 |
+
entity_type = next((t for t, w in zip(token_types, token_texts) if w == word), None)
|
| 175 |
return color_map.get(entity_type, "#FFFFFF")
|
| 176 |
|
| 177 |
wordcloud = WordCloud(width=800, height=400, background_color='black', color_func=color_func).generate_from_frequencies(word_freq)
|