Victoria Slocum commited on
Commit
74782aa
1 Parent(s): cb57978

fix: edits

Browse files
Files changed (1) hide show
  1. app.py +63 -48
app.py CHANGED
@@ -61,6 +61,17 @@ def token(text, attributes, model):
61
  data = pd.DataFrame(data, columns=attributes)
62
  return data
63
 
 
 
 
 
 
 
 
 
 
 
 
64
 
65
  def random_vectors(text, model):
66
  nlp = spacy.load(model + "_md")
@@ -131,55 +142,59 @@ def get_text(model):
131
  demo = gr.Blocks()
132
 
133
  with demo:
134
- model_input = gr.Dropdown(
135
- choices=models, value=DEFAULT_MODEL, interactive=True, label="Pretrained Pipelines")
136
- text_button = gr.Button("Get new text")
137
- text_input = gr.Textbox(
138
- value=DEFAULT_TEXT, interactive=True, label="Input Text")
139
- button = gr.Button("Generate")
140
- with gr.Tabs():
141
- with gr.TabItem("Dependency"):
142
- col_punct = gr.Checkbox(label="Collapse Punctuation", value=True)
143
- col_phrase = gr.Checkbox(label="Collapse Phrases", value=True)
144
- compact = gr.Checkbox(label="Compact", value=False)
145
- depen_output = gr.HTML()
146
- dep_button = gr.Button("Generate this tab")
147
- with gr.TabItem("Entity"):
148
- entity_input = gr.CheckboxGroup(DEFAULT_ENTS, value=DEFAULT_ENTS)
149
- entity_output = gr.HTML()
150
- ent_button = gr.Button("Generate this tab")
151
- with gr.TabItem("Tokens"):
152
- with gr.Column():
153
- tok_input = gr.CheckboxGroup(
154
- DEFAULT_TOK_ATTR, value=DEFAULT_TOK_ATTR)
155
- tok_output = gr.Dataframe(
156
- headers=DEFAULT_TOK_ATTR, overflow_row_behaviour="paginate")
157
- tok_button = gr.Button("Generate this tab")
158
- with gr.TabItem("Similarity"):
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
159
  with gr.Row():
160
- sim_text1 = gr.Textbox(
161
- value="Apple", label="Chosen", interactive=True,)
162
- sim_text2 = gr.Textbox(
163
- value="U.K. startup", label="Chosen", interactive=True,)
164
- sim_output = gr.Textbox(label="Similarity Score")
165
- sim_random_button = gr.Button("Generate random words")
166
- sim_button = gr.Button("Generate inputs")
167
- with gr.TabItem("Spans"):
168
- with gr.Column():
169
- with gr.Row():
170
- span1 = gr.Textbox(
171
- label="Span 1", value="U.K. startup", placeholder="Input a part of the sentence")
172
- label1 = gr.Textbox(value="ORG",
173
- label="Label for Span 1")
174
- with gr.Row():
175
- span2 = gr.Textbox(
176
- label="Span 2", value="U.K.", placeholder="Input another part of the sentence")
177
- label2 = gr.Textbox(value="GPE",
178
- label="Label for Span 2")
179
- span_output = gr.HTML()
180
- gr.Markdown(value="\n\n\n\n")
181
- gr.Markdown(value="\n\n\n\n")
182
- span_button = gr.Button("Generate this tab")
183
  text_button.click(get_text, inputs=[model_input], outputs=text_input)
184
  button.click(dependency, inputs=[
185
  text_input, col_punct, col_phrase, compact, model_input], outputs=depen_output)
 
61
  data = pd.DataFrame(data, columns=attributes)
62
  return data
63
 
64
+ def default_token(text, attributes, model):
65
+ nlp = spacy.load(model + "_sm")
66
+ data = []
67
+ doc = nlp(text)
68
+ for tok in doc:
69
+ tok_data = []
70
+ for attr in attributes:
71
+ tok_data.append(getattr(tok, attr))
72
+ data.append(tok_data)
73
+ return data
74
+
75
 
76
  def random_vectors(text, model):
77
  nlp = spacy.load(model + "_md")
 
142
  demo = gr.Blocks()
143
 
144
  with demo:
145
+ with gr.Box():
146
+ with gr.Row():
147
+ with gr.Row():
148
+ gr.Markdown("Chose a language model")
149
+ model_input = gr.Dropdown(
150
+ choices=models, value=DEFAULT_MODEL, interactive=True, label="Pretrained Pipelines")
151
+ text_button = gr.Button("Get text in new language")
152
+ with gr.Row():
153
+ text_input = gr.Textbox(
154
+ value=DEFAULT_TEXT, interactive=True, label="Input Text")
155
+ button = gr.Button("Generate", variant="primary")
156
+ with gr.Column():
157
+ gr.Markdown("Dependency Parser")
158
+ col_punct = gr.Checkbox(label="Collapse Punctuation", value=True)
159
+ col_phrase = gr.Checkbox(label="Collapse Phrases", value=True)
160
+ compact = gr.Checkbox(label="Compact", value=False)
161
+ depen_output = gr.HTML(value=dependency(DEFAULT_TEXT, True, True, False, DEFAULT_MODEL))
162
+ dep_button = gr.Button("Generate Dependency Parser")
163
+ gr.Markdown("Entity Recognizer")
164
+ entity_input = gr.CheckboxGroup(DEFAULT_ENTS, value=DEFAULT_ENTS)
165
+ entity_output = gr.HTML(value=entity(DEFAULT_TEXT, DEFAULT_ENTS, DEFAULT_MODEL))
166
+ ent_button = gr.Button("Generate Entity Recognizer")
167
+ gr.Markdown("Token Properties")
168
+ with gr.Column():
169
+ tok_input = gr.CheckboxGroup(
170
+ DEFAULT_TOK_ATTR, value=DEFAULT_TOK_ATTR)
171
+ tok_output = gr.Dataframe(value=default_token(DEFAULT_TEXT, DEFAULT_TOK_ATTR, DEFAULT_MODEL),overflow_row_behaviour="paginate")
172
+ tok_button = gr.Button("Generate Token Properties")
173
+ gr.Markdown("Word and Phrase Similarity")
174
+ with gr.Row():
175
+ sim_text1 = gr.Textbox(
176
+ value="Apple", label="Chosen", interactive=True,)
177
+ sim_text2 = gr.Textbox(
178
+ value="U.K. startup", label="Chosen", interactive=True,)
179
+ sim_output = gr.Textbox(label="Similarity Score", value="0.12")
180
+ sim_random_button = gr.Button("Generate random words")
181
+ sim_button = gr.Button("Generate similarity")
182
+ gr.Markdown("Spans")
183
+ with gr.Column():
184
+ with gr.Row():
185
+ span1 = gr.Textbox(
186
+ label="Span 1", value="U.K. startup", placeholder="Input a part of the sentence")
187
+ label1 = gr.Textbox(value="ORG",
188
+ label="Label for Span 1")
189
  with gr.Row():
190
+ span2 = gr.Textbox(
191
+ label="Span 2", value="U.K.", placeholder="Input another part of the sentence")
192
+ label2 = gr.Textbox(value="GPE",
193
+ label="Label for Span 2")
194
+ span_output = gr.HTML(value=span(DEFAULT_TEXT, "U.K. startup", "U.K.", "ORG", "GPE", DEFAULT_MODEL))
195
+ gr.Markdown(value="\n\n\n\n")
196
+ gr.Markdown(value="\n\n\n\n")
197
+ span_button = gr.Button("Generate spans")
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
198
  text_button.click(get_text, inputs=[model_input], outputs=text_input)
199
  button.click(dependency, inputs=[
200
  text_input, col_punct, col_phrase, compact, model_input], outputs=depen_output)