CoolFace
Apppublic

Grincon/Text_Analysis_demo

sourceHugging Faceunlicenseupdated 4y agoView on Hugging Face
0likes
app.py39 linesDownload Raw Back to root
1import spacy2from spacy import displacy3 4import gradio as gr5 6nlp = spacy.load("en_core_web_sm")7 8 9def text_analysis(text):10    doc = nlp(text)11    html = displacy.render(doc, style="dep", page=True)12    html = (13        ""14        + html15        + ""16    )17    pos_count = {18        "char_count": len(text),19        "token_count": 0,20    }21    pos_tokens = []22 23    for token in doc:24        pos_tokens.extend([(token.text, token.pos_), (" ", None)])25 26    return pos_tokens, pos_count, html27 28 29demo = gr.Interface(30    text_analysis,31    gr.Textbox(placeholder="Enter sentence here..."),32    ["highlight", "json", "html"],33    examples=[34        ["What a beautiful morning for a walk!"],35        ["It was the best of times, it was the worst of times."],36    ],37)38 39demo.launch()