Spaces:
Runtime error
Runtime error
Create new file
Browse files
app.py
ADDED
|
@@ -0,0 +1,42 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import gradio as gr
|
| 2 |
+
import os
|
| 3 |
+
os.system('python -m spacy download en_core_web_sm')
|
| 4 |
+
import spacy
|
| 5 |
+
from spacy import displacy
|
| 6 |
+
|
| 7 |
+
nlp = spacy.load("en_core_web_sm")
|
| 8 |
+
|
| 9 |
+
def text_analysis(text):
|
| 10 |
+
doc = nlp(text)
|
| 11 |
+
html = displacy.render(doc, style="dep", page=True)
|
| 12 |
+
html = (
|
| 13 |
+
"<div style='max-width:100%; max-height:360px; overflow:auto'>"
|
| 14 |
+
+ html
|
| 15 |
+
+ "</div>"
|
| 16 |
+
)
|
| 17 |
+
pos_count = {
|
| 18 |
+
"char_count": len(text),
|
| 19 |
+
"token_count": 0,
|
| 20 |
+
}
|
| 21 |
+
pos_tokens = []
|
| 22 |
+
|
| 23 |
+
rows = []
|
| 24 |
+
for token in doc:
|
| 25 |
+
rows.append((token.text, token.lemma_, token.pos_, token.tag_, token.dep_,
|
| 26 |
+
token.shape_, token.is_alpha, token.is_stop))
|
| 27 |
+
|
| 28 |
+
table = pd.DataFrame(rows, columns = ["TEXT", "LEMMA","POS","TAG","DEP","SHAPE","ALPHA","STOP"])
|
| 29 |
+
|
| 30 |
+
return table, html
|
| 31 |
+
|
| 32 |
+
demo = gr.Interface(
|
| 33 |
+
text_analysis,
|
| 34 |
+
gr.Textbox(placeholder="Enter sentence here..."),
|
| 35 |
+
[gr.Dataframe(), "html"],
|
| 36 |
+
examples=[
|
| 37 |
+
["Data Science Dojo is the leading platform providing training in data science, data analytics, and machine learning."],
|
| 38 |
+
["It's the best time to execute the plan."],
|
| 39 |
+
],
|
| 40 |
+
)
|
| 41 |
+
|
| 42 |
+
demo.launch()
|