Victoria Slocum commited on
Commit
a83d8ed
1 Parent(s): 7991260
Files changed (1) hide show
  1. app.py +25 -17
app.py CHANGED
@@ -10,13 +10,12 @@ DEFAULT_TEXT = "Apple is looking at buying U.K. startup for $1 billion."
10
  DEFAULT_TOK_ATTR = ['idx', 'text', 'pos_', 'lemma_', 'shape_', 'dep_']
11
  DEFAULT_ENTS = ['CARDINAL', 'DATE', 'EVENT', 'FAC', 'GPE', 'LANGUAGE', 'LAW', 'LOC', 'MONEY',
12
  'NORP', 'ORDINAL', 'ORG', 'PERCENT', 'PERSON', 'PRODUCT', 'QUANTITY', 'TIME', 'WORK_OF_ART']
13
-
14
  texts = {"en": DEFAULT_TEXT, "ca": "Apple està buscant comprar una startup del Regne Unit per mil milions de dòlars", "da": "Apple overvejer at købe et britisk startup for 1 milliard dollar.", "de": "Die ganze Stadt ist ein Startup: Shenzhen ist das Silicon Valley für Hardware-Firmen",
15
  "el": "Η άνιση κατανομή του πλούτου και του εισοδήματος, η οποία έχει λάβει τρομερές διαστάσεις, δεν δείχνει τάσεις βελτίωσης.", "es": "Apple está buscando comprar una startup del Reino Unido por mil millones de dólares.", "fi": "Itseajavat autot siirtävät vakuutusvastuun autojen valmistajille", "fr": "Apple cherche à acheter une start-up anglaise pour 1 milliard de dollars", "it": "Apple vuole comprare una startup del Regno Unito per un miliardo di dollari",
16
  "ja": "アップルがイギリスの新興企業を10億ドルで購入を検討", "ko": "애플이 영국의 스타트업을 10억 달러에 인수하는 것을 알아보고 있다.", "lt": "Jaunikis pirmąją vestuvinę naktį iškeitė į areštinės gultą", "nb": "Apple vurderer å kjøpe britisk oppstartfirma for en milliard dollar.", "nl": "Apple overweegt om voor 1 miljard een U.K. startup te kopen",
17
  "pl": "Poczuł przyjemną woń mocnej kawy.", "pt": "Apple está querendo comprar uma startup do Reino Unido por 100 milhões de dólares", "ro": "Apple plănuiește să cumpere o companie britanică pentru un miliard de dolari", "ru": "Apple рассматривает возможность покупки стартапа из Соединённого Королевства за $1 млрд", "sv": "Apple överväger att köpa brittisk startup för 1 miljard dollar.", "zh": "作为语言而言,为世界使用人数最多的语言,目前世界有五分之一人口做为母语。"}
18
 
19
-
20
  def get_all_models():
21
  with open("requirements.txt") as f:
22
  content = f.readlines()
@@ -32,11 +31,11 @@ def get_all_models():
32
  models = get_all_models()
33
 
34
 
35
- def dependency(text, col_punct, col_phrase, compact, model):
36
  nlp = spacy.load(model + "_sm")
37
  doc = nlp(text)
38
  options = {"compact": compact, "collapse_phrases": col_phrase,
39
- "collapse_punct": col_punct}
40
  html = displacy.render(doc, style="dep", options=options)
41
  return html
42
 
@@ -150,13 +149,13 @@ with demo:
150
  model_input = gr.Dropdown(
151
  choices=models, value=DEFAULT_MODEL, interactive=True, label="Pretrained Pipelines")
152
  with gr.Column():
153
- gr.Markdown("")
154
  with gr.Column():
155
  gr.Markdown("")
156
  with gr.Column():
157
  gr.Markdown("")
158
 
159
- text_button = gr.Button("Get text in model language")
160
  with gr.Row():
161
  with gr.Column():
162
  text_input = gr.Textbox(
@@ -168,21 +167,30 @@ with demo:
168
  with gr.Tabs():
169
  with gr.TabItem(""):
170
  with gr.Column():
171
- gr.Markdown("### Dependency Parser")
172
- col_punct = gr.Checkbox(label="Collapse Punctuation", value=True)
173
- col_phrase = gr.Checkbox(label="Collapse Phrases", value=True)
174
- compact = gr.Checkbox(label="Compact", value=False)
175
- depen_output = gr.HTML(value=dependency(DEFAULT_TEXT, True, True, False, DEFAULT_MODEL))
 
 
 
 
 
 
 
 
176
  dep_button = gr.Button("Generate Dependency Parser")
 
177
  with gr.Box():
178
  with gr.Column():
179
- gr.Markdown("### Entity Recognizer")
180
  entity_input = gr.CheckboxGroup(DEFAULT_ENTS, value=DEFAULT_ENTS)
181
  entity_output = gr.HTML(value=entity(DEFAULT_TEXT, DEFAULT_ENTS, DEFAULT_MODEL))
182
  ent_button = gr.Button("Generate Entity Recognizer")
183
  with gr.Box():
184
  with gr.Column():
185
- gr.Markdown("### Token Properties")
186
  with gr.Column():
187
  tok_input = gr.CheckboxGroup(
188
  DEFAULT_TOK_ATTR, value=DEFAULT_TOK_ATTR)
@@ -190,7 +198,7 @@ with demo:
190
  tok_button = gr.Button("Generate Token Properties")
191
  with gr.Box():
192
  with gr.Column():
193
- gr.Markdown("### Word and Phrase Similarity")
194
  with gr.Row():
195
  sim_text1 = gr.Textbox(
196
  value="Apple", label="Word 1", interactive=True,)
@@ -201,7 +209,7 @@ with demo:
201
  sim_button = gr.Button("Generate similarity")
202
  with gr.Box():
203
  with gr.Column():
204
- gr.Markdown("### Spans")
205
  with gr.Column():
206
  with gr.Row():
207
  span1 = gr.Textbox(
@@ -220,7 +228,7 @@ with demo:
220
 
221
  text_button.click(get_text, inputs=[model_input], outputs=text_input)
222
  button.click(dependency, inputs=[
223
- text_input, col_punct, col_phrase, compact, model_input], outputs=depen_output)
224
  button.click(
225
  entity, inputs=[text_input, entity_input, model_input], outputs=entity_output)
226
  button.click(
@@ -230,7 +238,7 @@ with demo:
230
  button.click(
231
  span, inputs=[text_input, span1, span2, label1, label2, model_input], outputs=span_output)
232
  dep_button.click(dependency, inputs=[
233
- text_input, col_punct, col_phrase, compact, model_input], outputs=depen_output)
234
  ent_button.click(
235
  entity, inputs=[text_input, entity_input, model_input], outputs=entity_output)
236
  tok_button.click(
 
10
  DEFAULT_TOK_ATTR = ['idx', 'text', 'pos_', 'lemma_', 'shape_', 'dep_']
11
  DEFAULT_ENTS = ['CARDINAL', 'DATE', 'EVENT', 'FAC', 'GPE', 'LANGUAGE', 'LAW', 'LOC', 'MONEY',
12
  'NORP', 'ORDINAL', 'ORG', 'PERCENT', 'PERSON', 'PRODUCT', 'QUANTITY', 'TIME', 'WORK_OF_ART']
13
+ DEFAULT_COLOR = "linear-gradient(90deg, #FFCA74, #7AECEC)"
14
  texts = {"en": DEFAULT_TEXT, "ca": "Apple està buscant comprar una startup del Regne Unit per mil milions de dòlars", "da": "Apple overvejer at købe et britisk startup for 1 milliard dollar.", "de": "Die ganze Stadt ist ein Startup: Shenzhen ist das Silicon Valley für Hardware-Firmen",
15
  "el": "Η άνιση κατανομή του πλούτου και του εισοδήματος, η οποία έχει λάβει τρομερές διαστάσεις, δεν δείχνει τάσεις βελτίωσης.", "es": "Apple está buscando comprar una startup del Reino Unido por mil millones de dólares.", "fi": "Itseajavat autot siirtävät vakuutusvastuun autojen valmistajille", "fr": "Apple cherche à acheter une start-up anglaise pour 1 milliard de dollars", "it": "Apple vuole comprare una startup del Regno Unito per un miliardo di dollari",
16
  "ja": "アップルがイギリスの新興企業を10億ドルで購入を検討", "ko": "애플이 영국의 스타트업을 10억 달러에 인수하는 것을 알아보고 있다.", "lt": "Jaunikis pirmąją vestuvinę naktį iškeitė į areštinės gultą", "nb": "Apple vurderer å kjøpe britisk oppstartfirma for en milliard dollar.", "nl": "Apple overweegt om voor 1 miljard een U.K. startup te kopen",
17
  "pl": "Poczuł przyjemną woń mocnej kawy.", "pt": "Apple está querendo comprar uma startup do Reino Unido por 100 milhões de dólares", "ro": "Apple plănuiește să cumpere o companie britanică pentru un miliard de dolari", "ru": "Apple рассматривает возможность покупки стартапа из Соединённого Королевства за $1 млрд", "sv": "Apple överväger att köpa brittisk startup för 1 miljard dollar.", "zh": "作为语言而言,为世界使用人数最多的语言,目前世界有五分之一人口做为母语。"}
18
 
 
19
  def get_all_models():
20
  with open("requirements.txt") as f:
21
  content = f.readlines()
 
31
  models = get_all_models()
32
 
33
 
34
+ def dependency(text, col_punct, col_phrase, compact, bg, font, model):
35
  nlp = spacy.load(model + "_sm")
36
  doc = nlp(text)
37
  options = {"compact": compact, "collapse_phrases": col_phrase,
38
+ "collapse_punct": col_punct, "bg": bg, "color":font}
39
  html = displacy.render(doc, style="dep", options=options)
40
  return html
41
 
 
149
  model_input = gr.Dropdown(
150
  choices=models, value=DEFAULT_MODEL, interactive=True, label="Pretrained Pipelines")
151
  with gr.Column():
152
+ text_button = gr.Button("Get text in model language")
153
  with gr.Column():
154
  gr.Markdown("")
155
  with gr.Column():
156
  gr.Markdown("")
157
 
158
+
159
  with gr.Row():
160
  with gr.Column():
161
  text_input = gr.Textbox(
 
167
  with gr.Tabs():
168
  with gr.TabItem(""):
169
  with gr.Column():
170
+ gr.Markdown("## [Dependency Parser](https://spacy.io/usage/visualizers#dep)")
171
+ with gr.Row():
172
+ with gr.Column():
173
+ col_punct = gr.Checkbox(label="Collapse Punctuation", value=True)
174
+ col_phrase = gr.Checkbox(label="Collapse Phrases", value=True)
175
+ compact = gr.Checkbox(label="Compact", value=False)
176
+ with gr.Column():
177
+ bg = gr.Textbox(label="Background Color", value=DEFAULT_COLOR)
178
+ with gr.Column():
179
+ text = gr.Textbox(label="Text Color", value="black")
180
+ with gr.Column():
181
+ gr.Markdown("")
182
+ depen_output = gr.HTML(value=dependency(DEFAULT_TEXT, True, True, False, DEFAULT_COLOR, "black", DEFAULT_MODEL))
183
  dep_button = gr.Button("Generate Dependency Parser")
184
+ gr.Markdown("\n\n\n")
185
  with gr.Box():
186
  with gr.Column():
187
+ gr.Markdown("## [Entity Recognizer](https://spacy.io/usage/visualizers#ent)")
188
  entity_input = gr.CheckboxGroup(DEFAULT_ENTS, value=DEFAULT_ENTS)
189
  entity_output = gr.HTML(value=entity(DEFAULT_TEXT, DEFAULT_ENTS, DEFAULT_MODEL))
190
  ent_button = gr.Button("Generate Entity Recognizer")
191
  with gr.Box():
192
  with gr.Column():
193
+ gr.Markdown("## [Token Properties](https://spacy.io/usage/linguistic-features)")
194
  with gr.Column():
195
  tok_input = gr.CheckboxGroup(
196
  DEFAULT_TOK_ATTR, value=DEFAULT_TOK_ATTR)
 
198
  tok_button = gr.Button("Generate Token Properties")
199
  with gr.Box():
200
  with gr.Column():
201
+ gr.Markdown("## [Word and Phrase Similarity](https://spacy.io/usage/linguistic-features#vectors-similarity)")
202
  with gr.Row():
203
  sim_text1 = gr.Textbox(
204
  value="Apple", label="Word 1", interactive=True,)
 
209
  sim_button = gr.Button("Generate similarity")
210
  with gr.Box():
211
  with gr.Column():
212
+ gr.Markdown("## [Spans](https://spacy.io/usage/visualizers#span)")
213
  with gr.Column():
214
  with gr.Row():
215
  span1 = gr.Textbox(
 
228
 
229
  text_button.click(get_text, inputs=[model_input], outputs=text_input)
230
  button.click(dependency, inputs=[
231
+ text_input, col_punct, col_phrase, compact, bg, text, model_input], outputs=depen_output)
232
  button.click(
233
  entity, inputs=[text_input, entity_input, model_input], outputs=entity_output)
234
  button.click(
 
238
  button.click(
239
  span, inputs=[text_input, span1, span2, label1, label2, model_input], outputs=span_output)
240
  dep_button.click(dependency, inputs=[
241
+ text_input, col_punct, col_phrase, compact, bg, text, model_input], outputs=depen_output)
242
  ent_button.click(
243
  entity, inputs=[text_input, entity_input, model_input], outputs=entity_output)
244
  tok_button.click(