Spaces:
Runtime error
Runtime error
import gradio as gr | |
import os | |
os.system('python -m spacy download en_core_web_sm') | |
import spacy | |
from spacy import displacy | |
import pandas as pd | |
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 = [] | |
rows = [] | |
for token in doc: | |
rows.append((token.text, token.lemma_, token.pos_, token.tag_, token.dep_, | |
token.shape_, token.is_alpha, token.is_stop)) | |
table = pd.DataFrame(rows, columns = ["TEXT", "LEMMA","POS","TAG","DEP","SHAPE","ALPHA","STOP"]) | |
return table, html | |
demo = gr.Interface( | |
text_analysis, | |
gr.Textbox(placeholder="Enter sentence here..."), | |
[gr.Dataframe(), "html"], | |
examples=[ | |
["Data Science Dojo is the leading platform providing training in data science, data analytics, and machine learning."], | |
["It's the best time to execute the plan."], | |
], | |
) | |
demo.launch() |