gradio/demo/text_analysis.py
aliabid94 3bef9756fd
Allow for bulk input from examples (#74)
* bulk input first commit

* add titanic demo support

* remove flagged content

* route vendor files through gradio.app if share=True; cache bust other static files

* s

* navigate examples with arrow keys

* navigate examples with arrow keys

* navigate examples with arrow keys

Co-authored-by: Ali Abid <aliabid94@gmail.com>
2020-11-04 07:38:48 -08:00

40 lines
911 B
Python

# Demo: (Textbox) -> (HighlightedText, KeyValues, HTML)
import spacy
from spacy import displacy
import gradio as gr
nlp = spacy.load("en_core_web_sm")
def text_analysis(text):
doc = nlp(text)
html = displacy.render(doc, style="dep", page=True)
html = "<div style='max-width:100%; max-height:360px; overflow:auto'>" + html + "</div>"
pos_count = {
"char_count": len(text),
"token_count": 0,
}
pos_tokens = []
for token in doc:
pos_tokens.extend([(token.text, token.pos_), (" ", None)])
return pos_tokens, pos_count, html
io = gr.Interface(
text_analysis,
gr.inputs.Textbox(placeholder="Enter sentence here..."),
[
"highlight", "key_values", "html"
],
examples=[
["What a beautiful morning for a walk!"],
["It was the best of times, it was the worst of times."],
]
)
io.test_launch()
io.launch()