Update app.py
Browse files
app.py
CHANGED
|
@@ -42,6 +42,79 @@ def process_nlp(system_message):
|
|
| 42 |
colorized_text = colorize_text(system_message['content'])
|
| 43 |
return colorized_text
|
| 44 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 45 |
def colorize_text(text):
|
| 46 |
colorized_text = ""
|
| 47 |
lines = text.split("\n")
|
|
|
|
| 42 |
colorized_text = colorize_text(system_message['content'])
|
| 43 |
return colorized_text
|
| 44 |
|
| 45 |
+
# Define color combinations for different parts of speech
|
| 46 |
+
COLORS = {
|
| 47 |
+
"NOUN": "#FF3300",
|
| 48 |
+
"VERB": "#FFFF00",
|
| 49 |
+
"ADJ": "#00CC00",
|
| 50 |
+
"ADV": "#FF6600",
|
| 51 |
+
"digit": "#9900CC",
|
| 52 |
+
"punct": "#8B4513",
|
| 53 |
+
"quote": "#008080",
|
| 54 |
+
}
|
| 55 |
+
|
| 56 |
+
# Define color combinations for individuals with dyslexia
|
| 57 |
+
DYSLEXIA_COLORS = {
|
| 58 |
+
"NOUN": "#1E90FF",
|
| 59 |
+
"VERB": "#FFFF00",
|
| 60 |
+
"ADJ": "#00CED1",
|
| 61 |
+
"ADV": "#FF8C00",
|
| 62 |
+
"digit": "#800080",
|
| 63 |
+
"punct": "#A0522D",
|
| 64 |
+
"quote": "#ADFF2F",
|
| 65 |
+
}
|
| 66 |
+
|
| 67 |
+
# Define a dark background color
|
| 68 |
+
DARK_BG = "#212121"
|
| 69 |
+
|
| 70 |
+
def colorize_text(text, colors=None):
|
| 71 |
+
if colors is None:
|
| 72 |
+
colors = COLORS
|
| 73 |
+
|
| 74 |
+
colorized_text = ""
|
| 75 |
+
lines = text.split("\n")
|
| 76 |
+
|
| 77 |
+
for line in lines:
|
| 78 |
+
doc = nlp(line)
|
| 79 |
+
|
| 80 |
+
for token in doc:
|
| 81 |
+
if token.ent_type_:
|
| 82 |
+
colorized_text += f"**{token.text_with_ws}**"
|
| 83 |
+
else:
|
| 84 |
+
color = colors.get(token.pos_, None)
|
| 85 |
+
if color is not None:
|
| 86 |
+
colorized_text += (
|
| 87 |
+
f'<span style="color: {color}; '
|
| 88 |
+
f'background-color: transparent;">'
|
| 89 |
+
f"{token.text_with_ws}</span>"
|
| 90 |
+
)
|
| 91 |
+
elif token.is_digit:
|
| 92 |
+
colorized_text += (
|
| 93 |
+
f'<span style="color: {colors["digit"]}; '
|
| 94 |
+
f'background-color: transparent;">'
|
| 95 |
+
f"{token.text_with_ws}</span>"
|
| 96 |
+
)
|
| 97 |
+
elif token.is_punct:
|
| 98 |
+
colorized_text += (
|
| 99 |
+
f'<span style="color: {colors["punct"]}; '
|
| 100 |
+
f'background-color: transparent;">'
|
| 101 |
+
f"{token.text_with_ws}</span>"
|
| 102 |
+
)
|
| 103 |
+
elif token.is_quote:
|
| 104 |
+
colorized_text += (
|
| 105 |
+
f'<span style="color: {colors["quote"]}; '
|
| 106 |
+
f'background-color: transparent;">'
|
| 107 |
+
f"{token.text_with_ws}</span>"
|
| 108 |
+
)
|
| 109 |
+
else:
|
| 110 |
+
colorized_text += token.text_with_ws
|
| 111 |
+
|
| 112 |
+
colorized_text += "<br>"
|
| 113 |
+
|
| 114 |
+
return colorized_text
|
| 115 |
+
|
| 116 |
+
|
| 117 |
+
|
| 118 |
def colorize_text(text):
|
| 119 |
colorized_text = ""
|
| 120 |
lines = text.split("\n")
|