derek-thomas
commited on
Commit
·
bccd176
1
Parent(s):
7a277d3
Init commit
Browse files- .gitattributes +2 -0
- .gitignore +3 -0
- app.py +40 -0
.gitattributes
CHANGED
|
@@ -32,3 +32,5 @@ saved_model/**/* filter=lfs diff=lfs merge=lfs -text
|
|
| 32 |
*.zip filter=lfs diff=lfs merge=lfs -text
|
| 33 |
*.zst filter=lfs diff=lfs merge=lfs -text
|
| 34 |
*tfevents* filter=lfs diff=lfs merge=lfs -text
|
|
|
|
|
|
|
|
|
| 32 |
*.zip filter=lfs diff=lfs merge=lfs -text
|
| 33 |
*.zst filter=lfs diff=lfs merge=lfs -text
|
| 34 |
*tfevents* filter=lfs diff=lfs merge=lfs -text
|
| 35 |
+
models/ptb.biaffine.dep.roberta filter=lfs diff=lfs merge=lfs -text
|
| 36 |
+
models/ptb.biaffine.dep.lstm.char filter=lfs diff=lfs merge=lfs -text
|
.gitignore
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
.idea
|
| 2 |
+
notebooks/.ipynb_checkpoints
|
| 3 |
+
*.DS*
|
app.py
ADDED
|
@@ -0,0 +1,40 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import gradio as gr
|
| 2 |
+
|
| 3 |
+
from pathlib import Path
|
| 4 |
+
from supar import Parser
|
| 5 |
+
from spacy import displacy
|
| 6 |
+
from spacy.tokens import Doc, Span
|
| 7 |
+
import spacy
|
| 8 |
+
|
| 9 |
+
proj_dir = Path(__file__).parent
|
| 10 |
+
model_choices = [str(model.name) for model in (proj_dir / 'models').glob('*')][::-1]
|
| 11 |
+
|
| 12 |
+
|
| 13 |
+
def sentence_diagram(model_name, text, progress=gr.Progress(track_tqdm=True)):
|
| 14 |
+
parser = Parser.load(f'./models/{model_name}')
|
| 15 |
+
|
| 16 |
+
Span.set_extension("con_tree", getter=lambda x: parser.predict([i.text for i in x], verbose=False)[0], force=True)
|
| 17 |
+
nlp = spacy.load('en_core_web_sm')
|
| 18 |
+
doc = nlp(text)
|
| 19 |
+
|
| 20 |
+
options = {"compact": False, "color": "Red", 'collapse_punct': True, 'collapse_phrases': False,
|
| 21 |
+
'split_sentences': True}
|
| 22 |
+
html = displacy.render(doc, style="dep", options=options, page=True)
|
| 23 |
+
return html
|
| 24 |
+
|
| 25 |
+
|
| 26 |
+
with gr.Blocks() as demo:
|
| 27 |
+
with gr.Tab("Sentence Diagrams"):
|
| 28 |
+
model_name = gr.Dropdown(choices=model_choices, label='Model Name')
|
| 29 |
+
text_in = gr.Textbox(label='Sentence(s) to diagram', value='This is a test')
|
| 30 |
+
button = gr.Button('Run!')
|
| 31 |
+
html_out = gr.HTML()
|
| 32 |
+
with gr.Tab("Brother Hill Tribute"):
|
| 33 |
+
gr.Markdown("""To Bro Hill""")
|
| 34 |
+
|
| 35 |
+
button.click(sentence_diagram,
|
| 36 |
+
inputs=[model_name, text_in],
|
| 37 |
+
outputs=html_out)
|
| 38 |
+
|
| 39 |
+
if __name__ == '__main__':
|
| 40 |
+
demo.queue().launch(show_error=True)
|