Spaces:
Running
on
Zero
Running
on
Zero
Refactor app.py to utilize GPU allocation for NLP pipelines and update documentation for clarity and completeness
Browse files
app.py
CHANGED
@@ -1,13 +1,19 @@
|
|
|
|
1 |
import gradio as gr
|
2 |
from gr_nlp_toolkit import Pipeline
|
3 |
|
4 |
# Author: Lefteris Loukas
|
5 |
-
# Date:
|
6 |
-
# Description: A Gradio interface for the
|
7 |
# Point-of-Contact: http://nlp.cs.aueb.gr/
|
8 |
|
|
|
9 |
# Initialize Pipelines
|
10 |
-
|
|
|
|
|
|
|
|
|
11 |
|
12 |
G2G_PLACEHOLDER = "e.g., H thessaloniki einai mia poli sti boreia ellada"
|
13 |
NER_PLACEHOLDER = "e.g., Η Αργεντινή κέρδισε το Παγκόσμιο Κύπελλο το 2022"
|
@@ -15,16 +21,22 @@ POS_PLACEHOLDER = "e.g., Μου αρέσει να διαβάζω τα post το
|
|
15 |
DP_PLACEHOLDER = "e.g., Προτιμώ την πρωινή πτήση από την Αθήνα στη Θεσσαλονίκη."
|
16 |
|
17 |
|
|
|
18 |
def greeklish_to_greek(text):
|
19 |
if not text:
|
20 |
text = G2G_PLACEHOLDER[5:]
|
21 |
|
22 |
-
doc = nlp_pos_ner_dp_with_g2g(text)
|
|
|
|
|
23 |
return " ".join([token.text for token in doc.tokens])
|
24 |
|
25 |
|
|
|
26 |
def process_text(text, task):
|
27 |
-
doc = nlp_pos_ner_dp_with_g2g(text)
|
|
|
|
|
28 |
task_mapping = {
|
29 |
"dp": lambda token: f"Text: {token.text}, Head: {token.head}, Deprel: {token.deprel}",
|
30 |
"pos": lambda token: f"Text: {token.text}, UPOS: {token.upos}, Feats: {token.feats}",
|
@@ -58,8 +70,15 @@ def create_demo():
|
|
58 |
with gr.Blocks(theme=theme) as demo:
|
59 |
gr.Markdown(
|
60 |
"""
|
61 |
-
#
|
62 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
63 |
|
64 |
## Key Features:
|
65 |
- Named Entity Recognition (NER)
|
@@ -122,13 +141,28 @@ def create_demo():
|
|
122 |
|
123 |
## Github Repository
|
124 |
|
125 |
-
Visit the
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
126 |
|
127 |
## About the Project
|
128 |
|
129 |
-
[The Greek NLP Toolkit](
|
130 |
-
|
131 |
-
and Greeklish to Greek conversion. This project is part of ongoing research aimed at advancing Greek language processing capabilities.
|
132 |
<br>
|
133 |
<br>
|
134 |
|
|
|
1 |
+
import spaces # isort:skip
|
2 |
import gradio as gr
|
3 |
from gr_nlp_toolkit import Pipeline
|
4 |
|
5 |
# Author: Lefteris Loukas
|
6 |
+
# Date: January 2025
|
7 |
+
# Description: A Gradio interface for the Greek NLP Toolkit (gr-nlp-toolkit), which includes Greeklish to Greek conversion, dependency parsing, part-of-speech tagging, and named entity recognition.
|
8 |
# Point-of-Contact: http://nlp.cs.aueb.gr/
|
9 |
|
10 |
+
|
11 |
# Initialize Pipelines
|
12 |
+
@spaces.GPU
|
13 |
+
def allocate_pipeline():
|
14 |
+
nlp_pipeline = Pipeline("pos,ner,dp,g2g")
|
15 |
+
return nlp_pipeline
|
16 |
+
|
17 |
|
18 |
G2G_PLACEHOLDER = "e.g., H thessaloniki einai mia poli sti boreia ellada"
|
19 |
NER_PLACEHOLDER = "e.g., Η Αργεντινή κέρδισε το Παγκόσμιο Κύπελλο το 2022"
|
|
|
21 |
DP_PLACEHOLDER = "e.g., Προτιμώ την πρωινή πτήση από την Αθήνα στη Θεσσαλονίκη."
|
22 |
|
23 |
|
24 |
+
@spaces.GPU
|
25 |
def greeklish_to_greek(text):
|
26 |
if not text:
|
27 |
text = G2G_PLACEHOLDER[5:]
|
28 |
|
29 |
+
# doc = nlp_pos_ner_dp_with_g2g(text)
|
30 |
+
nlp_pipeline = allocate_pipeline()
|
31 |
+
doc = nlp_pipeline(text)
|
32 |
return " ".join([token.text for token in doc.tokens])
|
33 |
|
34 |
|
35 |
+
@spaces.GPU
|
36 |
def process_text(text, task):
|
37 |
+
# doc = nlp_pos_ner_dp_with_g2g(text)
|
38 |
+
nlp_pipeline = allocate_pipeline()
|
39 |
+
doc = nlp_pipeline(text)
|
40 |
task_mapping = {
|
41 |
"dp": lambda token: f"Text: {token.text}, Head: {token.head}, Deprel: {token.deprel}",
|
42 |
"pos": lambda token: f"Text: {token.text}, UPOS: {token.upos}, Feats: {token.feats}",
|
|
|
70 |
with gr.Blocks(theme=theme) as demo:
|
71 |
gr.Markdown(
|
72 |
"""
|
73 |
+
# GR-NLP-TOOLKIT Playground 🇬🇷
|
74 |
+
|
75 |
+
<p align="left">
|
76 |
+
<a href="https://github.com/nlpaueb/gr-nlp-toolkit">
|
77 |
+
<img src="https://github.com/nlpaueb/gr-nlp-toolkit/blob/main/logo.png?raw=true" width="200">
|
78 |
+
</a>
|
79 |
+
</p>
|
80 |
+
|
81 |
+
This is an interactive playground/demo for our open-source Python toolkit (`gr-nlp-toolkit`), which supports state-of-the-art natural language processing capabilities in Greek.
|
82 |
|
83 |
## Key Features:
|
84 |
- Named Entity Recognition (NER)
|
|
|
141 |
|
142 |
## Github Repository
|
143 |
|
144 |
+
Visit the <a href="https://github.com/nlpaueb/gr-nlp-toolkit" target="_blank">GitHub repository</a> for more information, such as documentation and full usage examples.
|
145 |
+
|
146 |
+
## Paper
|
147 |
+
The software was presented at COLING 2025. Read the full technical report/paper here: https://arxiv.org/abs/2412.08520
|
148 |
+
|
149 |
+
If you use our toolkit, please cite it:
|
150 |
+
```bibtex
|
151 |
+
@misc{loukas2024grnlptoolkitopensourcenlptoolkit,
|
152 |
+
title={GR-NLP-TOOLKIT: An Open-Source NLP Toolkit for Modern Greek},
|
153 |
+
author={Lefteris Loukas and Nikolaos Smyrnioudis and Chrysa Dikonomaki and Spyros Barbakos and Anastasios Toumazatos and John Koutsikakis and Manolis Kyriakakis and Mary Georgiou and Stavros Vassos and John Pavlopoulos and Ion Androutsopoulos},
|
154 |
+
year={2024},
|
155 |
+
eprint={2412.08520},
|
156 |
+
archivePrefix={arXiv},
|
157 |
+
primaryClass={cs.CL},
|
158 |
+
url={https://arxiv.org/abs/2412.08520},
|
159 |
+
}
|
160 |
+
```
|
161 |
|
162 |
## About the Project
|
163 |
|
164 |
+
[The Greek NLP Toolkit](https://github.com/nlpaueb/gr-nlp-toolkit) is the state-of-the-art natural language processing toolkit for modern Greek, maintained by the <a href="http://nlp.cs.aueb.gr/" target="_blank">Natural Language Processing Group at the Athens University of Economics and Business</a>.
|
165 |
+
For technical questions, contact us via Github issues. For licensing and commercial inquiries, please contact us via the Contact page in the website.
|
|
|
166 |
<br>
|
167 |
<br>
|
168 |
|