Spaces:
Runtime error
Runtime error
Victoria Slocum
commited on
Commit
·
74782aa
1
Parent(s):
cb57978
fix: edits
Browse files
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 |
-
|
| 135 |
-
|
| 136 |
-
|
| 137 |
-
|
| 138 |
-
|
| 139 |
-
|
| 140 |
-
|
| 141 |
-
|
| 142 |
-
|
| 143 |
-
|
| 144 |
-
|
| 145 |
-
|
| 146 |
-
|
| 147 |
-
|
| 148 |
-
|
| 149 |
-
|
| 150 |
-
|
| 151 |
-
|
| 152 |
-
|
| 153 |
-
|
| 154 |
-
|
| 155 |
-
|
| 156 |
-
|
| 157 |
-
|
| 158 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 159 |
with gr.Row():
|
| 160 |
-
|
| 161 |
-
|
| 162 |
-
|
| 163 |
-
|
| 164 |
-
|
| 165 |
-
|
| 166 |
-
|
| 167 |
-
|
| 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)
|