Spaces:
Runtime error
Runtime error
File size: 1,475 Bytes
5a72547 1b9089e 5a72547 a57f22c f3aeff2 a57f22c 5a72547 6fa2cc1 5a72547 6b1534a a57f22c a7e87da c149088 a7e87da c149088 a7e87da c149088 a7e87da 5a72547 a7e87da 5a72547 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 |
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)
dependency_parsing = displacy.render(doc, style="dep", page=True)
visual1 = (
"<div style='max-width:100%; overflow:auto'>"
+ dependency_parsing
+ "</div>"
)
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, visual1
with gr.Blocks() as demo:
with gr.Row():
inp = gr.Textbox(placeholder="Enter text to analyze...", label="Input")
btn = gr.Button("Analyze Text")
gr.Markdown("""
# Analysis""")
with gr.Row():
table = gr.Dataframe()
gr.Markdown("""## Dependency Parsing""")
with gr.Row():
visual1 = gr.HTML()
with gr.Row():
gr.Examples(
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."],
], fn=text_analysis, inputs=inp, outputs=[table, visual1], cache_examples=True)
btn.click(fn=text_analysis, inputs=inp, outputs=[table, visual1])
demo.launch() |