Spaces:
Running
on
Zero
Running
on
Zero
import gradio as gr | |
import spaces | |
from transformers import pipeline | |
import torch | |
DESCRIPTION=""" | |
This is the space for the Language Modeling Group at TABILAB in Computer Engineering of Bogazici University. | |
We released the first version of our Turkish language model TURNA. | |
This model is based on an encoder-decoder T5 architecture with 1.1B parameters. | |
For more details, please refer to our paper. | |
""" | |
sentiment_example = [["Bu üründen çok memnun kaldım."]] | |
long_text = [["Eyfel Kulesi (Fransızca: La tour Eiffel [la tuʀ ɛˈfɛl]), Paris'teki demir kule. Kule, aynı zamanda tüm dünyada Fransa'nın sembolü halini almıştır. İsmini, inşa ettiren Fransız inşaat mühendisi Gustave Eiffel'den alır.[1] En büyük turizm cazibelerinden biri olan Eyfel Kulesi, yılda 6 milyon turist çeker. 2002 yılında toplam ziyaretçi sayısı 200 milyona ulaşmıştır."]] | |
ner_example = [["Benim adım Turna."]] | |
t2t_example = [["Paraphrase: Bu üründen çok memnun kaldım."]] | |
nli_example = [["Bunu çok beğendim. Bunu çok sevdim."]] | |
#ttc = pipeline(model="boun-tabi-LMG/turna_classification_ttc4900", device=0) | |
# examples =long_text, title="Text Categorization") | |
#product_reviews = pipeline(model="boun-tabi-LMG/turna_classification_tr_product_reviews", device=0) | |
#title_gen = pipeline(model="boun-tabi-LMG/turna_title_generation_mlsum", device=0) | |
def nli(input, model_choice="turna_nli_nli_tr"): | |
nli_model = pipeline(model="boun-tabi-LMG/turna_nli_nli_tr", device=0) | |
stsb_model = pipeline(model="boun-tabi-LMG/turna_semantic_similarity_stsb_tr", device=0) | |
if model_choice=="turna_nli_nli_tr": | |
return nli_model(input) | |
else: | |
return stsb_model(input) | |
def nli(input, model_choice="turna_nli_nli_tr"): | |
nli_model = pipeline(model="boun-tabi-LMG/turna_nli_nli_tr", device=0) | |
stsb_model = pipeline(model="boun-tabi-LMG/turna_semantic_similarity_stsb_tr", device=0) | |
if model_choice=="turna_nli_nli_tr": | |
return nli_model(input) | |
else: | |
return stsb_model(input) | |
def sentiment_analysis(input, model_choice="turna_classification_17bintweet_sentiment"): | |
product_reviews = pipeline(model="boun-tabi-LMG/turna_classification_tr_product_reviews", device=0) | |
sentiment_model = pipeline(model="boun-tabi-LMG/turna_classification_17bintweet_sentiment", device=0) | |
if model_choice=="turna_classification_17bintweet_sentiment": | |
return sentiment_model(input) | |
else: | |
return product_reviews(input) | |
def nli_stsb(input, nli=True): | |
if nli==True: | |
return nli_model(input) | |
else: | |
return stsb_model(input) | |
def t2t(input): | |
return t2t_gen_model(input) | |
def pos(input, model_choice="turna_pos_imst"): | |
pos_imst = pipeline(model="boun-tabi-LMG/turna_pos_imst", device=0) | |
pos_boun = pipeline(model="boun-tabi-LMG/turna_pos_boun", device=0) | |
if model_choice=="turna_pos_imst": | |
return pos_imst(input) | |
else: | |
return pos_boun(input) | |
def ner(input, model_choice="turna_ner_wikiann"): | |
ner_model = pipeline(model="boun-tabi-LMG/turna_ner_milliyet", device=0) | |
ner_wikiann = pipeline(model="boun-tabi-LMG/turna_ner_wikiann", device=0) | |
if model_choice=="turna_ner_wikiann": | |
return ner_wikiann(input) | |
else: | |
return ner_model(input) | |
def paraphrase(input, model_choice="turna_paraphrasing_tatoeba"): | |
paraphrasing = pipeline(model="boun-tabi-LMG/turna_paraphrasing_tatoeba", device=0) | |
paraphrasing_sub = pipeline(model="boun-tabi-LMG/turna_paraphrasing_opensubtitles", device=0) | |
if model_choice=="turna_paraphrasing_tatoeba": | |
return paraphrasing(input) | |
else: | |
return paraphrasing_sub(input) | |
def summarize(input, model_choice="turna_summarization_tr_news"): | |
summarization_model = pipeline(model="boun-tabi-LMG/turna_summarization_mlsum", device=0) | |
news_sum = pipeline(model="boun-tabi-LMG/turna_summarization_tr_news", device=0) | |
if model_choice=="turna_summarization_tr_news": | |
return news_sum(input) | |
else: | |
return summarization_model(input) | |
with gr.Blocks(theme="soft") as demo: | |
gr.Markdown("# TURNA 🐦") | |
gr.Markdown(DESCRIPTION) | |
with gr.Tab("POS"): | |
gr.Markdown("TURNA fine-tuned on part-of-speech-tagging. Enter text to parse parts of speech and pick the model.") | |
with gr.Column(): | |
with gr.Row(): | |
pos_choice = gr.Radio(choices = ["turna_pos_imst", "turna_pos_boun"], label ="Model") | |
pos_input = gr.Textbox(label="POS Input") | |
pos_output = gr.Textbox(label="POS Output") | |
pos_submit = gr.Button() | |
pos_submit.click(pos, inputs=[pos_input, pos_choice], outputs=pos_output) | |
pos_examples = gr.Examples(examples = ner_example, inputs = [pos_input, pos_choice], outputs=pos_output, fn=pos) | |
with gr.Tab("NER"): | |
gr.Markdown("TURNA fine-tuned on named entity recognition. Enter text to parse named entities and pick the model.") | |
with gr.Column(): | |
with gr.Row(): | |
ner_choice = gr.Radio(choices = ["turna_ner_wikiann", "turna_ner_milliyet"], label ="Model") | |
ner_input = gr.Textbox(label="NER Input") | |
ner_output = gr.Textbox(label="NER Output") | |
ner_submit = gr.Button() | |
ner_submit.click(ner, inputs=[ner_input, ner_choice], outputs=ner_output) | |
ner_examples = gr.Examples(examples = ner_example, inputs = [ner_input, ner_choice], outputs=ner_output, fn=ner) | |
with gr.Tab("Paraphrase"): | |
gr.Markdown("TURNA fine-tuned on paraphrasing. Enter text to paraphrase and pick the model.") | |
with gr.Column(): | |
with gr.Row(): | |
paraphrasing_choice = gr.Radio(choices = ["turna_paraphrasing_tatoeba", "turna_paraphrasing_opensubtitles"], label ="Model") | |
paraphrasing_input = gr.Textbox(label = "Paraphrasing Input") | |
paraphrasing_output = gr.Text(label="Paraphrasing Output") | |
paraphrasing_submit = gr.Button() | |
paraphrasing_submit.click(paraphrase, inputs=[paraphrasing_input, paraphrasing_choice], outputs=paraphrasing_output) | |
paraphrase_examples = gr.Examples(examples = long_text, inputs = [paraphrasing_input, paraphrasing_choice], outputs=paraphrasing_output, fn=paraphrase) | |
with gr.Tab("Summarization"): | |
gr.Markdown("TURNA fine-tuned on summarization. Enter text to summarize and pick the model.") | |
with gr.Column(): | |
with gr.Row(): | |
sum_choice = gr.Radio(choices = ["turna_summarization_mlsum", "turna_summarization_tr_news"], label ="Model") | |
sum_input = gr.Textbox(label = "Summarization Input") | |
sum_output = gr.Textbox(label = "Summarization Output") | |
sum_submit = gr.Button() | |
sum_submit.click(summarize, inputs=[sum_input, sum_choice], outputs=sum_output) | |
sum_examples = gr.Examples(examples = long_text, inputs = [sum_input, sum_choice], outputs=sum_output, fn=summarize) | |
demo.launch() |