Create app.py
Browse files
app.py
ADDED
@@ -0,0 +1,38 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import gradio as gr
|
2 |
+
import os
|
3 |
+
os.system('python -m spacy download ko_core_news_sm')
|
4 |
+
import spacy
|
5 |
+
from spacy import displacy
|
6 |
+
|
7 |
+
nlp = spacy.load("ko_core_news_sm")
|
8 |
+
|
9 |
+
def text_analysis(text):
|
10 |
+
doc = nlp(text)
|
11 |
+
html = displacy.render(doc, style="dep", page=True)
|
12 |
+
html = (
|
13 |
+
""
|
14 |
+
+ html
|
15 |
+
+ ""
|
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, html
|
27 |
+
|
28 |
+
demo = gr.Interface(
|
29 |
+
text_analysis,
|
30 |
+
gr.Textbox(placeholder="Enter sentence here..."),
|
31 |
+
["highlight", "json", "html"],
|
32 |
+
examples=[
|
33 |
+
["์๋ฆ๋ค์ด ์ถ์ต๋ค์ ์ธ์ ๊ฐ ์ฌ๋ผ์ง๊ฒ ์ง๋ง"],
|
34 |
+
["์ง๊ธ์ด๋ผ๋ ๋
ธ๋๋ก ๋จ๊ธฐ๊ณ ์ถ์ด"],
|
35 |
+
],
|
36 |
+
)
|
37 |
+
|
38 |
+
demo.launch()
|