Victoria Slocum commited on
Commit
33ef7a6
1 Parent(s): 2e9de90

scrollbars suck

Browse files
Files changed (1) hide show
  1. app.py +94 -92
app.py CHANGED
@@ -37,7 +37,9 @@ def dependency(text, col_punct, col_phrase, compact, bg, font, model):
37
  doc = nlp(text)
38
  options = {"compact": compact, "collapse_phrases": col_phrase,
39
  "collapse_punct": col_punct, "bg": bg, "color": font}
40
- html = displacy.render(doc, style="dep", options=options)
 
 
41
  return html
42
 
43
 
@@ -164,109 +166,109 @@ with demo:
164
  with gr.Column():
165
  gr.Markdown("")
166
  button = gr.Button("Generate", variant="primary")
167
- with gr.Column():
168
- with gr.Tabs():
169
- with gr.TabItem(""):
170
- with gr.Column():
171
- gr.Markdown(
172
- "## [Dependency Parser](https://spacy.io/usage/visualizers#dep)")
173
- gr.Markdown(
174
- "The dependency visualizer, `dep`, shows part-of-speech tags and syntactic dependencies.")
175
- with gr.Row():
176
- with gr.Column():
177
- col_punct = gr.Checkbox(
178
- label="Collapse Punctuation", value=True)
179
- col_phrase = gr.Checkbox(
180
- label="Collapse Phrases", value=True)
181
- compact = gr.Checkbox(label="Compact", value=False)
182
- with gr.Column():
183
- bg = gr.Textbox(
184
- label="Background Color", value=DEFAULT_COLOR)
185
- with gr.Column():
186
- text = gr.Textbox(
187
- label="Text Color", value="black")
188
- depen_output = gr.HTML(value=dependency(
189
- DEFAULT_TEXT, True, True, False, DEFAULT_COLOR, "black", DEFAULT_MODEL))
190
- dep_button = gr.Button("Generate Dependency Parser")
191
- gr.Markdown("\n\n\n")
192
- with gr.Box():
193
  with gr.Column():
194
  gr.Markdown(
195
- "## [Entity Recognizer](https://spacy.io/usage/visualizers#ent)")
196
  gr.Markdown(
197
- "The entity visualizer, `ent`, highlights named entities and their labels in a text.")
198
- entity_input = gr.CheckboxGroup(
199
- DEFAULT_ENTS, value=DEFAULT_ENTS)
200
- entity_output = gr.HTML(value=entity(
201
- DEFAULT_TEXT, DEFAULT_ENTS, DEFAULT_MODEL))
202
- ent_button = gr.Button("Generate Entity Recognizer")
203
- with gr.Box():
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
204
  with gr.Column():
205
- gr.Markdown(
206
- "## [Token Properties](https://spacy.io/usage/linguistic-features)")
207
- gr.Markdown("When you put in raw text to spaCy, it returns a `Doc` object with different linguistic features")
 
 
 
 
 
 
 
 
 
 
 
 
208
  with gr.Column():
209
- with gr.Row():
210
- with gr.Column():
211
- tok_input = gr.CheckboxGroup(
212
- DEFAULT_TOK_ATTR, value=DEFAULT_TOK_ATTR)
213
- with gr.Column():
214
- gr.Markdown("")
215
- tok_output = gr.Dataframe(headers=DEFAULT_TOK_ATTR, value=default_token(
216
- DEFAULT_TEXT, DEFAULT_TOK_ATTR, DEFAULT_MODEL), overflow_row_behaviour="paginate")
217
- tok_button = gr.Button("Generate Token Properties")
218
- with gr.Box():
 
 
 
 
 
 
 
219
  with gr.Column():
220
- gr.Markdown(
221
- "## [Word and Phrase Similarity](https://spacy.io/usage/linguistic-features#vectors-similarity)")
222
- gr.Markdown("Words and spans have similarity ratings based off of their word vectors, or word embeddings")
223
  with gr.Row():
224
  with gr.Column():
225
- sim_text1 = gr.Textbox(
226
- value="Apple", label="Word 1", interactive=True,)
227
  with gr.Column():
228
- sim_text2 = gr.Textbox(
229
- value="U.K. startup", label="Word 2", interactive=True,)
230
  with gr.Column():
231
- sim_output = gr.Textbox(
232
- label="Similarity Score", value="0.12")
233
  with gr.Column():
234
  gr.Markdown("")
235
- sim_random_button = gr.Button("Generate random words")
236
- sim_button = gr.Button("Generate similarity")
237
- with gr.Box():
238
- with gr.Column():
239
- gr.Markdown(
240
- "## [Spans](https://spacy.io/usage/visualizers#span)")
241
- gr.Markdown("The span visualizer, `span`, highlights overlapping spans in a text.")
242
- with gr.Column():
243
- with gr.Row():
244
- with gr.Column():
245
- span1 = gr.Textbox(
246
- label="Span 1", value="U.K. startup", placeholder="Input a part of the sentence")
247
- with gr.Column():
248
- label1 = gr.Textbox(value="ORG",
249
- label="Label for Span 1")
250
- with gr.Column():
251
- gr.Markdown("")
252
- with gr.Column():
253
- gr.Markdown("")
254
- with gr.Row():
255
- with gr.Column():
256
- span2 = gr.Textbox(
257
- label="Span 2", value="U.K.", placeholder="Input another part of the sentence")
258
- with gr.Column():
259
- label2 = gr.Textbox(value="GPE",
260
- label="Label for Span 2")
261
- with gr.Column():
262
- gr.Markdown("")
263
- with gr.Column():
264
- gr.Markdown("")
265
- span_output = gr.HTML(value=span(
266
- DEFAULT_TEXT, "U.K. startup", "U.K.", "ORG", "GPE", DEFAULT_MODEL))
267
- gr.Markdown(value="\n\n\n\n")
268
- gr.Markdown(value="\n\n\n\n")
269
- span_button = gr.Button("Generate spans")
270
 
271
  text_button.click(get_text, inputs=[model_input], outputs=text_input)
272
  button.click(dependency, inputs=[
 
37
  doc = nlp(text)
38
  options = {"compact": compact, "collapse_phrases": col_phrase,
39
  "collapse_punct": col_punct, "bg": bg, "color": font}
40
+ html = '<div style="overflow-x: auto; min-width:101%;">'
41
+ html = html + displacy.render(doc, style="dep", options=options) + '</div>'
42
+ print(html)
43
  return html
44
 
45
 
 
166
  with gr.Column():
167
  gr.Markdown("")
168
  button = gr.Button("Generate", variant="primary")
169
+ with gr.Tabs():
170
+ with gr.TabItem(""):
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
171
  with gr.Column():
172
  gr.Markdown(
173
+ "## [Dependency Parser](https://spacy.io/usage/visualizers#dep)")
174
  gr.Markdown(
175
+ "The dependency visualizer, `dep`, shows part-of-speech tags and syntactic dependencies.")
176
+ with gr.Row():
177
+ with gr.Column():
178
+ col_punct = gr.Checkbox(
179
+ label="Collapse Punctuation", value=True)
180
+ col_phrase = gr.Checkbox(
181
+ label="Collapse Phrases", value=True)
182
+ compact = gr.Checkbox(label="Compact", value=False)
183
+ with gr.Column():
184
+ bg = gr.Textbox(
185
+ label="Background Color", value=DEFAULT_COLOR)
186
+ with gr.Column():
187
+ text = gr.Textbox(
188
+ label="Text Color", value="black")
189
+ with gr.Row():
190
+ with gr.Column():
191
+ depen_output = gr.HTML(value=dependency(
192
+ DEFAULT_TEXT, True, True, False, DEFAULT_COLOR, "black", DEFAULT_MODEL))
193
+ dep_button = gr.Button("Generate Dependency Parser")
194
+ with gr.Box():
195
+ with gr.Column():
196
+ gr.Markdown(
197
+ "## [Entity Recognizer](https://spacy.io/usage/visualizers#ent)")
198
+ gr.Markdown(
199
+ "The entity visualizer, `ent`, highlights named entities and their labels in a text.")
200
+ entity_input = gr.CheckboxGroup(
201
+ DEFAULT_ENTS, value=DEFAULT_ENTS)
202
+ entity_output = gr.HTML(value=entity(
203
+ DEFAULT_TEXT, DEFAULT_ENTS, DEFAULT_MODEL))
204
+ ent_button = gr.Button("Generate Entity Recognizer")
205
+ with gr.Box():
206
+ with gr.Column():
207
+ gr.Markdown(
208
+ "## [Token Properties](https://spacy.io/usage/linguistic-features)")
209
+ gr.Markdown("When you put in raw text to spaCy, it returns a `Doc` object with different linguistic features")
210
  with gr.Column():
211
+ with gr.Row():
212
+ with gr.Column():
213
+ tok_input = gr.CheckboxGroup(
214
+ DEFAULT_TOK_ATTR, value=DEFAULT_TOK_ATTR)
215
+ with gr.Column():
216
+ gr.Markdown("")
217
+ tok_output = gr.Dataframe(headers=DEFAULT_TOK_ATTR, value=default_token(
218
+ DEFAULT_TEXT, DEFAULT_TOK_ATTR, DEFAULT_MODEL), overflow_row_behaviour="paginate")
219
+ tok_button = gr.Button("Generate Token Properties")
220
+ with gr.Box():
221
+ with gr.Column():
222
+ gr.Markdown(
223
+ "## [Word and Phrase Similarity](https://spacy.io/usage/linguistic-features#vectors-similarity)")
224
+ gr.Markdown("Words and spans have similarity ratings based off of their word vectors, or word embeddings")
225
+ with gr.Row():
226
  with gr.Column():
227
+ sim_text1 = gr.Textbox(
228
+ value="Apple", label="Word 1", interactive=True,)
229
+ with gr.Column():
230
+ sim_text2 = gr.Textbox(
231
+ value="U.K. startup", label="Word 2", interactive=True,)
232
+ with gr.Column():
233
+ sim_output = gr.Textbox(
234
+ label="Similarity Score", value="0.12")
235
+ with gr.Column():
236
+ gr.Markdown("")
237
+ sim_random_button = gr.Button("Generate random words")
238
+ sim_button = gr.Button("Generate similarity")
239
+ with gr.Box():
240
+ with gr.Column():
241
+ gr.Markdown(
242
+ "## [Spans](https://spacy.io/usage/visualizers#span)")
243
+ gr.Markdown("The span visualizer, `span`, highlights overlapping spans in a text.")
244
  with gr.Column():
 
 
 
245
  with gr.Row():
246
  with gr.Column():
247
+ span1 = gr.Textbox(
248
+ label="Span 1", value="U.K. startup", placeholder="Input a part of the sentence")
249
  with gr.Column():
250
+ label1 = gr.Textbox(value="ORG",
251
+ label="Label for Span 1")
252
  with gr.Column():
253
+ gr.Markdown("")
 
254
  with gr.Column():
255
  gr.Markdown("")
256
+ with gr.Row():
257
+ with gr.Column():
258
+ span2 = gr.Textbox(
259
+ label="Span 2", value="U.K.", placeholder="Input another part of the sentence")
260
+ with gr.Column():
261
+ label2 = gr.Textbox(value="GPE",
262
+ label="Label for Span 2")
263
+ with gr.Column():
264
+ gr.Markdown("")
265
+ with gr.Column():
266
+ gr.Markdown("")
267
+ span_output = gr.HTML(value=span(
268
+ DEFAULT_TEXT, "U.K. startup", "U.K.", "ORG", "GPE", DEFAULT_MODEL))
269
+ gr.Markdown(value="\n\n\n\n")
270
+ gr.Markdown(value="\n\n\n\n")
271
+ span_button = gr.Button("Generate spans")
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
272
 
273
  text_button.click(get_text, inputs=[model_input], outputs=text_input)
274
  button.click(dependency, inputs=[