Spaces:
Runtime error
Runtime error
Victoria Slocum
commited on
Commit
•
c8d67a4
1
Parent(s):
96daa57
fix: token and sim update
Browse files- .gitignore +1 -0
- app.py +30 -19
.gitignore
ADDED
@@ -0,0 +1 @@
|
|
|
|
|
1 |
+
venv
|
app.py
CHANGED
@@ -60,7 +60,7 @@ def token(text, attributes, model):
|
|
60 |
return data
|
61 |
|
62 |
|
63 |
-
def
|
64 |
nlp = spacy.load(model + "_md")
|
65 |
doc = nlp(text)
|
66 |
n_chunks = [chunk for chunk in doc.noun_chunks]
|
@@ -71,6 +71,11 @@ def vectors(text, model):
|
|
71 |
return round(choice[0].similarity(choice[1]), 2), choice[0].text, choice[1].text
|
72 |
|
73 |
|
|
|
|
|
|
|
|
|
|
|
74 |
def span(text, span1, span2, label1, label2, model):
|
75 |
nlp = spacy.load(model + "_sm")
|
76 |
doc = nlp(text)
|
@@ -125,9 +130,10 @@ demo = gr.Blocks()
|
|
125 |
|
126 |
with demo:
|
127 |
model_input = gr.Dropdown(
|
128 |
-
choices=models, value=DEFAULT_MODEL, interactive=True)
|
129 |
text_button = gr.Button("Get new text")
|
130 |
-
text_input = gr.Textbox(
|
|
|
131 |
button = gr.Button("Generate")
|
132 |
with gr.Tabs():
|
133 |
with gr.TabItem("Dependency"):
|
@@ -144,24 +150,28 @@ with demo:
|
|
144 |
with gr.Column():
|
145 |
tok_input = gr.CheckboxGroup(
|
146 |
DEFAULT_TOK_ATTR, value=DEFAULT_TOK_ATTR)
|
147 |
-
tok_output = gr.Dataframe(
|
148 |
-
headers=DEFAULT_TOK_ATTR, overflow_row_behaviour="paginate")
|
149 |
tok_button = gr.Button("Generate this tab")
|
150 |
with gr.TabItem("Similarity"):
|
151 |
with gr.Row():
|
152 |
-
sim_text1 = gr.Textbox(
|
153 |
-
|
154 |
-
|
155 |
-
|
|
|
|
|
|
|
156 |
with gr.TabItem("Spans"):
|
157 |
with gr.Column():
|
158 |
with gr.Row():
|
159 |
-
span1 = gr.Textbox(
|
160 |
-
|
|
|
161 |
label="Label for Span 1")
|
162 |
with gr.Row():
|
163 |
-
span2 = gr.Textbox(
|
164 |
-
|
|
|
165 |
label="Label for Span 2")
|
166 |
span_output = gr.HTML()
|
167 |
gr.Markdown(value="\n\n\n\n")
|
@@ -174,8 +184,8 @@ with demo:
|
|
174 |
entity, inputs=[text_input, entity_input, model_input], outputs=entity_output)
|
175 |
button.click(
|
176 |
token, inputs=[text_input, tok_input, model_input], outputs=tok_output)
|
177 |
-
button.click(vectors, inputs=[
|
178 |
-
|
179 |
button.click(
|
180 |
span, inputs=[text_input, span1, span2, label1, label2, model_input], outputs=span_output)
|
181 |
dep_button.click(dependency, inputs=[
|
@@ -183,10 +193,11 @@ with demo:
|
|
183 |
ent_button.click(
|
184 |
entity, inputs=[text_input, entity_input, model_input], outputs=entity_output)
|
185 |
tok_button.click(
|
186 |
-
token, inputs=[text_input, tok_input, model_input], outputs=tok_output)
|
187 |
-
sim_button.click(vectors, inputs=[
|
188 |
-
|
189 |
span_button.click(
|
190 |
span, inputs=[text_input, span1, span2, label1, label2, model_input], outputs=span_output)
|
191 |
-
|
|
|
192 |
demo.launch()
|
|
|
60 |
return data
|
61 |
|
62 |
|
63 |
+
def random_vectors(text, model):
|
64 |
nlp = spacy.load(model + "_md")
|
65 |
doc = nlp(text)
|
66 |
n_chunks = [chunk for chunk in doc.noun_chunks]
|
|
|
71 |
return round(choice[0].similarity(choice[1]), 2), choice[0].text, choice[1].text
|
72 |
|
73 |
|
74 |
+
def vectors(input1, input2, model):
|
75 |
+
nlp = spacy.load(model + "_md")
|
76 |
+
return round(nlp(input1).similarity(nlp(input2)), 2)
|
77 |
+
|
78 |
+
|
79 |
def span(text, span1, span2, label1, label2, model):
|
80 |
nlp = spacy.load(model + "_sm")
|
81 |
doc = nlp(text)
|
|
|
130 |
|
131 |
with demo:
|
132 |
model_input = gr.Dropdown(
|
133 |
+
choices=models, value=DEFAULT_MODEL, interactive=True, label="Pretrained Pipelines")
|
134 |
text_button = gr.Button("Get new text")
|
135 |
+
text_input = gr.Textbox(
|
136 |
+
value=DEFAULT_TEXT, interactive=True, label="Input Text")
|
137 |
button = gr.Button("Generate")
|
138 |
with gr.Tabs():
|
139 |
with gr.TabItem("Dependency"):
|
|
|
150 |
with gr.Column():
|
151 |
tok_input = gr.CheckboxGroup(
|
152 |
DEFAULT_TOK_ATTR, value=DEFAULT_TOK_ATTR)
|
153 |
+
tok_output = gr.Dataframe(overflow_row_behaviour="paginate")
|
|
|
154 |
tok_button = gr.Button("Generate this tab")
|
155 |
with gr.TabItem("Similarity"):
|
156 |
with gr.Row():
|
157 |
+
sim_text1 = gr.Textbox(
|
158 |
+
value="Apple", label="Chosen", interactive=True,)
|
159 |
+
sim_text2 = gr.Textbox(
|
160 |
+
value="U.K. startup", label="Chosen", interactive=True,)
|
161 |
+
sim_output = gr.Textbox(label="Similarity Score")
|
162 |
+
sim_random_button = gr.Button("Generate random words")
|
163 |
+
sim_button = gr.Button("Generate inputs")
|
164 |
with gr.TabItem("Spans"):
|
165 |
with gr.Column():
|
166 |
with gr.Row():
|
167 |
+
span1 = gr.Textbox(
|
168 |
+
label="Span 1", value="U.K. startup", placeholder="Input a part of the sentence")
|
169 |
+
label1 = gr.Textbox(value="ORG",
|
170 |
label="Label for Span 1")
|
171 |
with gr.Row():
|
172 |
+
span2 = gr.Textbox(
|
173 |
+
label="Span 2", value="U.K.", placeholder="Input another part of the sentence")
|
174 |
+
label2 = gr.Textbox(value="GPE",
|
175 |
label="Label for Span 2")
|
176 |
span_output = gr.HTML()
|
177 |
gr.Markdown(value="\n\n\n\n")
|
|
|
184 |
entity, inputs=[text_input, entity_input, model_input], outputs=entity_output)
|
185 |
button.click(
|
186 |
token, inputs=[text_input, tok_input, model_input], outputs=tok_output)
|
187 |
+
button.click(vectors, inputs=[sim_text1,
|
188 |
+
sim_text2, model_input], outputs=sim_output)
|
189 |
button.click(
|
190 |
span, inputs=[text_input, span1, span2, label1, label2, model_input], outputs=span_output)
|
191 |
dep_button.click(dependency, inputs=[
|
|
|
193 |
ent_button.click(
|
194 |
entity, inputs=[text_input, entity_input, model_input], outputs=entity_output)
|
195 |
tok_button.click(
|
196 |
+
token, inputs=[text_input, tok_input, model_input], outputs=[tok_output])
|
197 |
+
sim_button.click(vectors, inputs=[
|
198 |
+
sim_text1, sim_text2, model_input], outputs=sim_output)
|
199 |
span_button.click(
|
200 |
span, inputs=[text_input, span1, span2, label1, label2, model_input], outputs=span_output)
|
201 |
+
sim_random_button.click(random_vectors, inputs=[text_input, model_input], outputs=[
|
202 |
+
sim_output, sim_text1, sim_text2])
|
203 |
demo.launch()
|