import spaces # isort:skip import gradio as gr from gr_nlp_toolkit import Pipeline # Author: Lefteris Loukas # Date: January 2025 # 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. # Point-of-Contact: http://nlp.cs.aueb.gr/ # Initialize Pipelines @spaces.GPU def allocate_pipeline(): nlp_pipeline = Pipeline("pos,ner,dp,g2g") return nlp_pipeline G2G_PLACEHOLDER = "e.g., H thessaloniki einai mia poli sti boreia ellada" NER_PLACEHOLDER = "e.g., Η Αργεντινή κέρδισε το Παγκόσμιο Κύπελλο το 2022" POS_PLACEHOLDER = "e.g., Μου αρέσει να διαβάζω τα post του Andrew Ng στο Twitter." DP_PLACEHOLDER = "e.g., Προτιμώ την πρωινή πτήση από την Αθήνα στη Θεσσαλονίκη." @spaces.GPU def greeklish_to_greek(text): if not text: text = G2G_PLACEHOLDER[5:] # doc = nlp_pos_ner_dp_with_g2g(text) nlp_pipeline = allocate_pipeline() doc = nlp_pipeline(text) return " ".join([token.text for token in doc.tokens]) @spaces.GPU def process_text(text, task): # doc = nlp_pos_ner_dp_with_g2g(text) nlp_pipeline = allocate_pipeline() doc = nlp_pipeline(text) task_mapping = { "dp": lambda token: f"Text: {token.text}, Head: {token.head}, Deprel: {token.deprel}", "pos": lambda token: f"Text: {token.text}, UPOS: {token.upos}, Feats: {token.feats}", "ner": lambda token: f"Text: {token.text}, NER: {token.ner}", } return "\n".join([task_mapping[task](token) for token in doc.tokens]) def dependency_parsing(text): if not text: text = DP_PLACEHOLDER[5:] return process_text(text, "dp") def pos_tagging(text): if not text: text = POS_PLACEHOLDER[5:] return process_text(text, "pos") def named_entity_recognition(text): if not text: text = NER_PLACEHOLDER[5:] return process_text(text, "ner") # Define the Gradio interface def create_demo(): theme = gr.themes.Soft() with gr.Blocks(theme=theme) as demo: gr.Markdown( """ # GR-NLP-TOOLKIT Playground 🇬🇷
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. ## Key Features: - Named Entity Recognition (NER) - Part-of-Speech (POS) Tagging - Morphological Tagging - Dependency Parsing (DP) - Greeklish to Greek Conversion (G2G) """ ) with gr.Tab("Named Entity Recognition"): ner_input = gr.Textbox( label="Enter text", placeholder=NER_PLACEHOLDER, ) ner_output = gr.Textbox(label="NER annotations") ner_button = gr.Button("Submit") ner_button.click( named_entity_recognition, inputs=ner_input, outputs=ner_output ) with gr.Tab("POS and Morphological Tagging"): pos_input = gr.Textbox( label="Enter text", placeholder=POS_PLACEHOLDER, ) pos_output = gr.Textbox(label="POS and Morphological Tagging annotations") pos_button = gr.Button("Submit") pos_button.click(pos_tagging, inputs=pos_input, outputs=pos_output) with gr.Tab("Dependency Parsing"): dp_input = gr.Textbox( label="Enter text", placeholder=DP_PLACEHOLDER, ) dp_output = gr.Textbox(label="Dependency Parsing annotations") dp_button = gr.Button("Submit") dp_button.click(dependency_parsing, inputs=dp_input, outputs=dp_output) with gr.Tab("Greeklish to Greek"): g2g_input = gr.Textbox( label="Enter Greeklish text", placeholder=G2G_PLACEHOLDER, ) g2g_output = gr.Textbox(label="Greek text") g2g_button = gr.Button("Submit") g2g_button.click(greeklish_to_greek, inputs=g2g_input, outputs=g2g_output) gr.Markdown( """ ## Installation The Greek NLP toolkit is available on PyPI for Python 3.9+: ```sh pip install gr-nlp-toolkit ``` ## Github Repository Visit the GitHub repository for more information, such as documentation and full usage examples. ## Paper The software was presented at COLING 2025. Read the full technical report/paper here: https://arxiv.org/abs/2412.08520 If you use our toolkit, please cite it: ```bibtex @misc{loukas-etal-2025-greek-nlp-toolkit, title={GR-NLP-TOOLKIT: An Open-Source NLP Toolkit for Modern Greek}, 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}, year={2025}, eprint={2412.08520}, archivePrefix={arXiv}, primaryClass={cs.CL}, url={https://arxiv.org/abs/2412.08520}, } ``` ## About the Project [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 Natural Language Processing Group at the Athens University of Economics and Business. For technical questions, contact us via Github issues. For licensing and commercial inquiries, please contact us via the Contact page in the website.