Spaces:
son9john
/
Runtime error

son9john commited on
Commit
2cdd680
1 Parent(s): 5f740b0

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +177 -42
app.py CHANGED
@@ -44,9 +44,153 @@ def process_nlp(system_message):
44
 
45
  from colour import Color
46
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
47
  # define color combinations for different parts of speech
48
  COLORS = {
49
- "NOUN": "#000000", # Black
50
  "VERB": "#ff6936", # Orange
51
  "ADJ": "#4363d8", # Blue
52
  "ADV": "#228b22", # Green
@@ -55,34 +199,28 @@ COLORS = {
55
  "quote": "#b300b3" # Magenta
56
  }
57
 
58
- # define color combinations for individuals with dyslexia and color vision deficiencies
59
  DYSLEXIA_COLORS = {
60
- "NOUN": "#000000",
61
  "VERB": "#ff6936",
62
  "ADJ": "#4363d8",
63
  "ADV": "#228b22",
64
  "digit": "#9a45d6",
65
  "punct": "#ffcc00",
66
- "quote": "#b300b3",
67
- }
68
- RED_GREEN_COLORS = {
69
- "NOUN": "#000000",
70
- "VERB": "#fe642e", # Lighter orange
71
- "ADJ": "#2e86c1", # Lighter blue
72
- "ADV": "#82e0aa", # Lighter green
73
- "digit": "#aa6c39", # Brown
74
- "punct": "#f0b27a", # Lighter yellow
75
- "quote": "#9932cc" # Darker magenta
76
  }
77
 
78
  # define a muted background color
79
- BACKGROUND_COLOR = "#ffffff" # White
80
 
81
  # define font and size
82
- FONT = "OpenDyslexic"
83
- FONT_SIZE = "18px"
84
 
85
- def colorize_text(text, colors=DYSLEXIA_COLORS, background_color=None, font=FONT, font_size=FONT_SIZE):
 
 
 
86
  if colors is None:
87
  colors = COLORS
88
  colorized_text = ""
@@ -110,20 +248,20 @@ def colorize_text(text, colors=DYSLEXIA_COLORS, background_color=None, font=FONT
110
  colorized_text += (
111
  f'<span style="color: {color}; '
112
  f'background-color: {background_color}; '
113
- f'font-family: {font}; '
114
- f'font-size: {font_size}; '
115
  f'font-weight: bold; '
116
  f'text-decoration: none; '
117
- f'padding-right: 0.5em;">'
118
  f"{token.text}</span>"
119
  )
120
  else:
121
  colorized_text += (
122
- f'<span style="font-family: {font}; '
123
- f'font-size: {font_size}; '
124
  f'font-weight: bold; '
125
  f'text-decoration: none; '
126
- f'padding-right: 0.5em;">'
127
  f"{token.text}</span>"
128
  )
129
  else:
@@ -133,59 +271,56 @@ def colorize_text(text, colors=DYSLEXIA_COLORS, background_color=None, font=FONT
133
  colorized_text += (
134
  f'<span style="color: {color}; '
135
  f'background-color: {background_color}; '
136
- f'font-family: {font}; '
137
- f'font-size: {font_size}; '
138
  f'font-weight: bold; '
139
  f'text-decoration: none; '
140
- f'padding-right: 0.5em;">'
141
  f"{token.text}</span>"
142
  )
143
  elif token.is_digit:
144
  colorized_text += (
145
  f'<span style="color: {colors["digit"]}; '
146
  f'background-color: {background_color}; '
147
- f'font-family: {font}; '
148
- f'font-size: {font_size}; '
149
  f'font-weight: bold; '
150
  f'text-decoration: none; '
151
- f'padding-right: 0.5em;">'
152
  f"{token.text}</span>"
153
  )
154
  elif token.is_punct:
155
  colorized_text += (
156
  f'<span style="color: {colors["punct"]}; '
157
  f'background-color: {background_color}; '
158
- f'font-family: {font}; '
159
- f'font-size: {font_size}; '
160
  f'font-weight: bold; '
161
  f'text-decoration: none; '
162
- f'padding-right: 0.5em;">'
163
  f"{token.text}</span>"
164
  )
165
  elif token.is_quote:
166
  colorized_text += (
167
  f'<span style="color: {colors["quote"]}; '
168
  f'background-color: {background_color}; '
169
- f'font-family: {font}; '
170
- f'font-size: {font_size}; '
171
  f'text-decoration: none; '
172
- f'padding-right: 0.5em;">'
173
  f"{token.text}</span>"
174
  )
175
  else:
176
- # use larger font size for specific parts of speech, such as nouns and verbs
177
- font_size = FONT_SIZE
178
- if token.pos_ in ["NOUN", "VERB"]:
179
- font_size = "22px"
180
  colorized_text += (
181
- f'<span style="font-family: {font}; '
182
- f'font-size: {font_size}; '
183
  f'font-weight: bold; '
184
  f'text-decoration: none; '
185
- f'padding-right: 0.5em;">'
186
  f"{token.text}</span>"
187
  )
188
  colorized_text += "<br>"
 
189
  return colorized_text
190
 
191
 
 
44
 
45
  from colour import Color
46
 
47
+ # # define color combinations for different parts of speech
48
+ # COLORS = {
49
+ # "NOUN": "#000000", # Black
50
+ # "VERB": "#ff6936", # Orange
51
+ # "ADJ": "#4363d8", # Blue
52
+ # "ADV": "#228b22", # Green
53
+ # "digit": "#9a45d6", # Purple
54
+ # "punct": "#ffcc00", # Yellow
55
+ # "quote": "#b300b3" # Magenta
56
+ # }
57
+
58
+ # # define color combinations for individuals with dyslexia and color vision deficiencies
59
+ # DYSLEXIA_COLORS = {
60
+ # "NOUN": "#000000",
61
+ # "VERB": "#ff6936",
62
+ # "ADJ": "#4363d8",
63
+ # "ADV": "#228b22",
64
+ # "digit": "#9a45d6",
65
+ # "punct": "#ffcc00",
66
+ # "quote": "#b300b3",
67
+ # }
68
+ # RED_GREEN_COLORS = {
69
+ # "NOUN": "#000000",
70
+ # "VERB": "#fe642e", # Lighter orange
71
+ # "ADJ": "#2e86c1", # Lighter blue
72
+ # "ADV": "#82e0aa", # Lighter green
73
+ # "digit": "#aa6c39", # Brown
74
+ # "punct": "#f0b27a", # Lighter yellow
75
+ # "quote": "#9932cc" # Darker magenta
76
+ # }
77
+
78
+ # # define a muted background color
79
+ # BACKGROUND_COLOR = "#ffffff" # White
80
+
81
+ # # define font and size
82
+ # FONT = "OpenDyslexic"
83
+ # FONT_SIZE = "18px"
84
+
85
+ # def colorize_text(text, colors=DYSLEXIA_COLORS, background_color=None, font=FONT, font_size=FONT_SIZE):
86
+ # if colors is None:
87
+ # colors = COLORS
88
+ # colorized_text = ""
89
+ # lines = text.split("\n")
90
+
91
+ # # set background color
92
+ # if background_color is None:
93
+ # background_color = BACKGROUND_COLOR
94
+
95
+ # # iterate over the lines in the text
96
+ # for line in lines:
97
+ # # parse the line with the language model
98
+ # doc = nlp(line)
99
+ # # iterate over the tokens in the line
100
+ # for token in doc:
101
+ # # check if the token is an entity
102
+ # if token.ent_type_:
103
+ # # use dyslexia colors for entity if available
104
+ # if colors == COLORS:
105
+ # color = DYSLEXIA_COLORS.get(token.pos_, None)
106
+ # else:
107
+ # color = colors.get(token.pos_, None)
108
+ # # check if a color is available for the token
109
+ # if color is not None:
110
+ # colorized_text += (
111
+ # f'<span style="color: {color}; '
112
+ # f'background-color: {background_color}; '
113
+ # f'font-family: {font}; '
114
+ # f'font-size: {font_size}; '
115
+ # f'font-weight: bold; '
116
+ # f'text-decoration: none; '
117
+ # f'padding-right: 0.5em;">'
118
+ # f"{token.text}</span>"
119
+ # )
120
+ # else:
121
+ # colorized_text += (
122
+ # f'<span style="font-family: {font}; '
123
+ # f'font-size: {font_size}; '
124
+ # f'font-weight: bold; '
125
+ # f'text-decoration: none; '
126
+ # f'padding-right: 0.5em;">'
127
+ # f"{token.text}</span>"
128
+ # )
129
+ # else:
130
+ # # check if a color is available for the token
131
+ # color = colors.get(token.pos_, None)
132
+ # if color is not None:
133
+ # colorized_text += (
134
+ # f'<span style="color: {color}; '
135
+ # f'background-color: {background_color}; '
136
+ # f'font-family: {font}; '
137
+ # f'font-size: {font_size}; '
138
+ # f'font-weight: bold; '
139
+ # f'text-decoration: none; '
140
+ # f'padding-right: 0.5em;">'
141
+ # f"{token.text}</span>"
142
+ # )
143
+ # elif token.is_digit:
144
+ # colorized_text += (
145
+ # f'<span style="color: {colors["digit"]}; '
146
+ # f'background-color: {background_color}; '
147
+ # f'font-family: {font}; '
148
+ # f'font-size: {font_size}; '
149
+ # f'font-weight: bold; '
150
+ # f'text-decoration: none; '
151
+ # f'padding-right: 0.5em;">'
152
+ # f"{token.text}</span>"
153
+ # )
154
+ # elif token.is_punct:
155
+ # colorized_text += (
156
+ # f'<span style="color: {colors["punct"]}; '
157
+ # f'background-color: {background_color}; '
158
+ # f'font-family: {font}; '
159
+ # f'font-size: {font_size}; '
160
+ # f'font-weight: bold; '
161
+ # f'text-decoration: none; '
162
+ # f'padding-right: 0.5em;">'
163
+ # f"{token.text}</span>"
164
+ # )
165
+ # elif token.is_quote:
166
+ # colorized_text += (
167
+ # f'<span style="color: {colors["quote"]}; '
168
+ # f'background-color: {background_color}; '
169
+ # f'font-family: {font}; '
170
+ # f'font-size: {font_size}; '
171
+ # f'text-decoration: none; '
172
+ # f'padding-right: 0.5em;">'
173
+ # f"{token.text}</span>"
174
+ # )
175
+ # else:
176
+ # # use larger font size for specific parts of speech, such as nouns and verbs
177
+ # font_size = FONT_SIZE
178
+ # if token.pos_ in ["NOUN", "VERB"]:
179
+ # font_size = "22px"
180
+ # colorized_text += (
181
+ # f'<span style="font-family: {font}; '
182
+ # f'font-size: {font_size}; '
183
+ # f'font-weight: bold; '
184
+ # f'text-decoration: none; '
185
+ # f'padding-right: 0.5em;">'
186
+ # f"{token.text}</span>"
187
+ # )
188
+ # colorized_text += "<br>"
189
+ # return colorized_text
190
+
191
  # define color combinations for different parts of speech
192
  COLORS = {
193
+ "NOUN": "#5e5e5e", # Dark gray
194
  "VERB": "#ff6936", # Orange
195
  "ADJ": "#4363d8", # Blue
196
  "ADV": "#228b22", # Green
 
199
  "quote": "#b300b3" # Magenta
200
  }
201
 
202
+ # define color combinations for individuals with dyslexia
203
  DYSLEXIA_COLORS = {
204
+ "NOUN": "#5e5e5e",
205
  "VERB": "#ff6936",
206
  "ADJ": "#4363d8",
207
  "ADV": "#228b22",
208
  "digit": "#9a45d6",
209
  "punct": "#ffcc00",
210
+ "quote": "#b300b3"
 
 
 
 
 
 
 
 
 
211
  }
212
 
213
  # define a muted background color
214
+ BACKGROUND_COLOR = "#f5f5f5" # Light gray
215
 
216
  # define font and size
217
+ FONT = "Arial"
218
+ FONT_SIZE = "14px"
219
 
220
+ # load the English language model
221
+ nlp = spacy.load('en_core_web_sm')
222
+
223
+ def colorize_text(text, colors=DYSLEXIA_COLORS, background_color=None):
224
  if colors is None:
225
  colors = COLORS
226
  colorized_text = ""
 
248
  colorized_text += (
249
  f'<span style="color: {color}; '
250
  f'background-color: {background_color}; '
251
+ f'font-family: {FONT}; '
252
+ f'font-size: {FONT_SIZE}; '
253
  f'font-weight: bold; '
254
  f'text-decoration: none; '
255
+ f'padding-right: 0.5em;">' # Add space between tokens
256
  f"{token.text}</span>"
257
  )
258
  else:
259
  colorized_text += (
260
+ f'<span style="font-family: {FONT}; '
261
+ f'font-size: {FONT_SIZE}; '
262
  f'font-weight: bold; '
263
  f'text-decoration: none; '
264
+ f'padding-right: 0.5em;">' # Add space between tokens
265
  f"{token.text}</span>"
266
  )
267
  else:
 
271
  colorized_text += (
272
  f'<span style="color: {color}; '
273
  f'background-color: {background_color}; '
274
+ f'font-family: {FONT}; '
275
+ f'font-size: {FONT_SIZE}; '
276
  f'font-weight: bold; '
277
  f'text-decoration: none; '
278
+ f'padding-right: 0.5em;">' # Add space between tokens
279
  f"{token.text}</span>"
280
  )
281
  elif token.is_digit:
282
  colorized_text += (
283
  f'<span style="color: {colors["digit"]}; '
284
  f'background-color: {background_color}; '
285
+ f'font-family: {FONT}; '
286
+ f'font-size: {FONT_SIZE}; '
287
  f'font-weight: bold; '
288
  f'text-decoration: none; '
289
+ f'padding-right: 0.5em;">' # Add space between tokens
290
  f"{token.text}</span>"
291
  )
292
  elif token.is_punct:
293
  colorized_text += (
294
  f'<span style="color: {colors["punct"]}; '
295
  f'background-color: {background_color}; '
296
+ f'font-family: {FONT}; '
297
+ f'font-size: {FONT_SIZE}; '
298
  f'font-weight: bold; '
299
  f'text-decoration: none; '
300
+ f'padding-right: 0.5em;">' # Add space between tokens
301
  f"{token.text}</span>"
302
  )
303
  elif token.is_quote:
304
  colorized_text += (
305
  f'<span style="color: {colors["quote"]}; '
306
  f'background-color: {background_color}; '
307
+ f'font-family: {FONT}; '
308
+ f'font-size: {FONT_SIZE}; '
309
  f'text-decoration: none; '
310
+ f'padding-right: 0.5em;">' # Add space between tokens
311
  f"{token.text}</span>"
312
  )
313
  else:
 
 
 
 
314
  colorized_text += (
315
+ f'<span style="font-family: {FONT}; '
316
+ f'font-size: {FONT_SIZE}; '
317
  f'font-weight: bold; '
318
  f'text-decoration: none; '
319
+ f'padding-right: 0.5em;">' # Add space between tokens
320
  f"{token.text}</span>"
321
  )
322
  colorized_text += "<br>"
323
+
324
  return colorized_text
325
 
326