Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
@@ -12,7 +12,7 @@ This model is based on an encoder-decoder T5 architecture with 1.1B parameters.
|
|
12 |
|
13 |
For more details, please refer to our paper.
|
14 |
|
15 |
-
Note
|
16 |
|
17 |
"""
|
18 |
|
@@ -24,44 +24,31 @@ t2t_example = [["Paraphrase: Bu üründen çok memnun kaldım."]]
|
|
24 |
nli_example = [["Bunu çok beğendim. Bunu çok sevdim."]]
|
25 |
|
26 |
|
27 |
-
#ttc = pipeline(model="boun-tabi-LMG/turna_classification_ttc4900", device=0)
|
28 |
-
# examples =long_text, title="Text Categorization")
|
29 |
-
#product_reviews = pipeline(model="boun-tabi-LMG/turna_classification_tr_product_reviews", device=0)
|
30 |
-
#title_gen = pipeline(model="boun-tabi-LMG/turna_title_generation_mlsum", device=0)
|
31 |
|
32 |
|
33 |
@spaces.GPU
|
34 |
def nli(input, model_choice="turna_nli_nli_tr"):
|
35 |
-
|
36 |
-
stsb_model = pipeline(model="boun-tabi-LMG/turna_semantic_similarity_stsb_tr", device=0)
|
37 |
-
|
38 |
if model_choice=="turna_nli_nli_tr":
|
|
|
39 |
return nli_model(input)[0]["generated_text"]
|
40 |
else:
|
41 |
-
|
42 |
|
43 |
-
@spaces.GPU
|
44 |
-
def nli(input, model_choice="turna_nli_nli_tr"):
|
45 |
-
nli_model = pipeline(model="boun-tabi-LMG/turna_nli_nli_tr", device=0)
|
46 |
-
stsb_model = pipeline(model="boun-tabi-LMG/turna_semantic_similarity_stsb_tr", device=0)
|
47 |
-
|
48 |
-
if model_choice=="turna_nli_nli_tr":
|
49 |
-
return nli_model(input)[0]["generated_text"]
|
50 |
-
else:
|
51 |
return stsb_model(input)[0]["generated_text"]
|
52 |
|
|
|
53 |
@spaces.GPU
|
54 |
def sentiment_analysis(input, model_choice="turna_classification_17bintweet_sentiment"):
|
55 |
-
product_reviews = pipeline(model="boun-tabi-LMG/turna_classification_tr_product_reviews", device=0)
|
56 |
-
sentiment_model = pipeline(model="boun-tabi-LMG/turna_classification_17bintweet_sentiment", device=0)
|
57 |
if model_choice=="turna_classification_17bintweet_sentiment":
|
|
|
|
|
58 |
return sentiment_model(input)[0]["generated_text"]
|
59 |
else:
|
|
|
|
|
60 |
return product_reviews(input)[0]["generated_text"]
|
61 |
|
62 |
-
@spaces.GPU
|
63 |
-
def t2t(input):
|
64 |
-
return t2t_gen_model(input)
|
65 |
|
66 |
@spaces.GPU
|
67 |
def pos(input, model_choice="turna_pos_imst"):
|
@@ -84,20 +71,22 @@ def ner(input, model_choice="turna_ner_wikiann"):
|
|
84 |
|
85 |
@spaces.GPU
|
86 |
def paraphrase(input, model_choice="turna_paraphrasing_tatoeba"):
|
87 |
-
paraphrasing = pipeline(model="boun-tabi-LMG/turna_paraphrasing_tatoeba", device=0)
|
88 |
-
paraphrasing_sub = pipeline(model="boun-tabi-LMG/turna_paraphrasing_opensubtitles", device=0)
|
89 |
if model_choice=="turna_paraphrasing_tatoeba":
|
|
|
90 |
return paraphrasing(input)[0]["generated_text"]
|
91 |
else:
|
|
|
|
|
92 |
return paraphrasing_sub(input)[0]["generated_text"]
|
93 |
|
94 |
@spaces.GPU
|
95 |
def summarize(input, model_choice="turna_summarization_tr_news"):
|
96 |
-
summarization_model = pipeline(model="boun-tabi-LMG/turna_summarization_mlsum", device=0)
|
97 |
-
news_sum = pipeline(model="boun-tabi-LMG/turna_summarization_tr_news", device=0)
|
98 |
if model_choice=="turna_summarization_tr_news":
|
|
|
|
|
99 |
return news_sum(input)[0]["generated_text"]
|
100 |
else:
|
|
|
101 |
return summarization_model(input)[0]["generated_text"]
|
102 |
|
103 |
|
@@ -105,15 +94,44 @@ def summarize(input, model_choice="turna_summarization_tr_news"):
|
|
105 |
with gr.Blocks(theme="soft") as demo:
|
106 |
gr.Markdown("# TURNA 🐦")
|
107 |
gr.Markdown(DESCRIPTION)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
108 |
with gr.Tab("POS"):
|
109 |
gr.Markdown("TURNA fine-tuned on part-of-speech-tagging. Enter text to parse parts of speech and pick the model.")
|
110 |
with gr.Column():
|
111 |
with gr.Row():
|
112 |
with gr.Column():
|
113 |
-
pos_choice = gr.Radio(choices = ["turna_pos_imst", "turna_pos_boun"], label ="Model")
|
114 |
pos_input = gr.Textbox(label="POS Input")
|
115 |
-
|
116 |
pos_submit = gr.Button()
|
|
|
117 |
pos_submit.click(pos, inputs=[pos_input, pos_choice], outputs=pos_output)
|
118 |
pos_examples = gr.Examples(examples = ner_example, inputs = [pos_input, pos_choice], outputs=pos_output, fn=pos)
|
119 |
|
@@ -122,7 +140,7 @@ with gr.Blocks(theme="soft") as demo:
|
|
122 |
with gr.Column():
|
123 |
with gr.Row():
|
124 |
with gr.Column():
|
125 |
-
ner_choice = gr.Radio(choices = ["turna_ner_wikiann", "turna_ner_milliyet"], label ="Model")
|
126 |
ner_input = gr.Textbox(label="NER Input")
|
127 |
ner_submit = gr.Button()
|
128 |
ner_output = gr.Textbox(label="NER Output")
|
@@ -134,10 +152,10 @@ with gr.Blocks(theme="soft") as demo:
|
|
134 |
with gr.Column():
|
135 |
with gr.Row():
|
136 |
with gr.Column():
|
137 |
-
paraphrasing_choice = gr.Radio(choices = ["turna_paraphrasing_tatoeba", "turna_paraphrasing_opensubtitles"], label ="Model")
|
138 |
paraphrasing_input = gr.Textbox(label = "Paraphrasing Input")
|
139 |
paraphrasing_submit = gr.Button()
|
140 |
-
|
141 |
|
142 |
paraphrasing_submit.click(paraphrase, inputs=[paraphrasing_input, paraphrasing_choice], outputs=paraphrasing_output)
|
143 |
paraphrase_examples = gr.Examples(examples = long_text, inputs = [paraphrasing_input, paraphrasing_choice], outputs=paraphrasing_output, fn=paraphrase)
|
@@ -146,7 +164,7 @@ with gr.Blocks(theme="soft") as demo:
|
|
146 |
with gr.Column():
|
147 |
with gr.Row():
|
148 |
with gr.Column():
|
149 |
-
sum_choice = gr.Radio(choices = ["turna_summarization_mlsum", "turna_summarization_tr_news"], label ="Model")
|
150 |
sum_input = gr.Textbox(label = "Summarization Input")
|
151 |
sum_submit = gr.Button()
|
152 |
sum_output = gr.Textbox(label = "Summarization Output")
|
|
|
12 |
|
13 |
For more details, please refer to our paper.
|
14 |
|
15 |
+
**Note:** First inference might take time as the models are downloaded on-the-go.
|
16 |
|
17 |
"""
|
18 |
|
|
|
24 |
nli_example = [["Bunu çok beğendim. Bunu çok sevdim."]]
|
25 |
|
26 |
|
|
|
|
|
|
|
|
|
27 |
|
28 |
|
29 |
@spaces.GPU
|
30 |
def nli(input, model_choice="turna_nli_nli_tr"):
|
31 |
+
|
|
|
|
|
32 |
if model_choice=="turna_nli_nli_tr":
|
33 |
+
nli_model = pipeline(model="boun-tabi-LMG/turna_nli_nli_tr", device=0)
|
34 |
return nli_model(input)[0]["generated_text"]
|
35 |
else:
|
36 |
+
stsb_model = pipeline(model="boun-tabi-LMG/turna_semantic_similarity_stsb_tr", device=0)
|
37 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
38 |
return stsb_model(input)[0]["generated_text"]
|
39 |
|
40 |
+
|
41 |
@spaces.GPU
|
42 |
def sentiment_analysis(input, model_choice="turna_classification_17bintweet_sentiment"):
|
|
|
|
|
43 |
if model_choice=="turna_classification_17bintweet_sentiment":
|
44 |
+
sentiment_model = pipeline(model="boun-tabi-LMG/turna_classification_17bintweet_sentiment", device=0)
|
45 |
+
|
46 |
return sentiment_model(input)[0]["generated_text"]
|
47 |
else:
|
48 |
+
product_reviews = pipeline(model="boun-tabi-LMG/turna_classification_tr_product_reviews", device=0)
|
49 |
+
|
50 |
return product_reviews(input)[0]["generated_text"]
|
51 |
|
|
|
|
|
|
|
52 |
|
53 |
@spaces.GPU
|
54 |
def pos(input, model_choice="turna_pos_imst"):
|
|
|
71 |
|
72 |
@spaces.GPU
|
73 |
def paraphrase(input, model_choice="turna_paraphrasing_tatoeba"):
|
|
|
|
|
74 |
if model_choice=="turna_paraphrasing_tatoeba":
|
75 |
+
paraphrasing = pipeline(model="boun-tabi-LMG/turna_paraphrasing_tatoeba", device=0)
|
76 |
return paraphrasing(input)[0]["generated_text"]
|
77 |
else:
|
78 |
+
paraphrasing_sub = pipeline(model="boun-tabi-LMG/turna_paraphrasing_opensubtitles", device=0)
|
79 |
+
|
80 |
return paraphrasing_sub(input)[0]["generated_text"]
|
81 |
|
82 |
@spaces.GPU
|
83 |
def summarize(input, model_choice="turna_summarization_tr_news"):
|
|
|
|
|
84 |
if model_choice=="turna_summarization_tr_news":
|
85 |
+
news_sum = pipeline(model="boun-tabi-LMG/turna_summarization_tr_news", device=0)
|
86 |
+
|
87 |
return news_sum(input)[0]["generated_text"]
|
88 |
else:
|
89 |
+
summarization_model = pipeline(model="boun-tabi-LMG/turna_summarization_mlsum", device=0)
|
90 |
return summarization_model(input)[0]["generated_text"]
|
91 |
|
92 |
|
|
|
94 |
with gr.Blocks(theme="soft") as demo:
|
95 |
gr.Markdown("# TURNA 🐦")
|
96 |
gr.Markdown(DESCRIPTION)
|
97 |
+
|
98 |
+
with gr.Tab("Sentiment Analysis"):
|
99 |
+
gr.Markdown("TURNA fine-tuned on sentiment analysis. Enter text to analyse sentiment and pick the model (tweets or product reviews).")
|
100 |
+
with gr.Column():
|
101 |
+
with gr.Row():
|
102 |
+
with gr.Column():
|
103 |
+
sentiment_choice = gr.Radio(choices = ["turna_classification_17bintweet_sentiment", "turna_classification_tr_product_reviews"], label ="Model", value="turna_classification_17bintweet_sentiment")
|
104 |
+
sentiment_input = gr.Textbox(label="Sentiment Analysis Input")
|
105 |
+
|
106 |
+
sentiment_submit = gr.Button()
|
107 |
+
sentiment_output = gr.Textbox(label="Sentiment Analysis Output")
|
108 |
+
sentiment_submit.click(nli, inputs=[pos_input, nli_choice], outputs=pos_output)
|
109 |
+
sentiment_examples = gr.Examples(examples = sentiment_example, inputs = [sentiment_input, sentiment_choice], outputs=sentiment_output, fn=sentiment)
|
110 |
+
|
111 |
+
|
112 |
+
with gr.Tab("NLI"):
|
113 |
+
gr.Markdown("TURNA fine-tuned on natural language inference. Enter text to infer entailment and pick the model. You can also check for semantic similarity entailment.")
|
114 |
+
with gr.Column():
|
115 |
+
with gr.Row():
|
116 |
+
with gr.Column():
|
117 |
+
nli_choice = gr.Radio(choices = ["turna_nli_nli_tr", "turna_semantic_similarity_stsb_tr"], label ="Model", value="turna_nli_nli_tr")
|
118 |
+
nli_input = gr.Textbox(label="NLI Input")
|
119 |
+
|
120 |
+
nli_submit = gr.Button()
|
121 |
+
nli_output = gr.Textbox(label="NLI Output")
|
122 |
+
nli_submit.click(nli, inputs=[pos_input, nli_choice], outputs=pos_output)
|
123 |
+
nli_examples = gr.Examples(examples = nli_example, inputs = [nli_input, nli_choice], outputs=nli_output, fn=nli)
|
124 |
+
|
125 |
with gr.Tab("POS"):
|
126 |
gr.Markdown("TURNA fine-tuned on part-of-speech-tagging. Enter text to parse parts of speech and pick the model.")
|
127 |
with gr.Column():
|
128 |
with gr.Row():
|
129 |
with gr.Column():
|
130 |
+
pos_choice = gr.Radio(choices = ["turna_pos_imst", "turna_pos_boun"], label ="Model", value="turna_pos_imst")
|
131 |
pos_input = gr.Textbox(label="POS Input")
|
132 |
+
|
133 |
pos_submit = gr.Button()
|
134 |
+
pos_output = gr.Textbox(label="POS Output")
|
135 |
pos_submit.click(pos, inputs=[pos_input, pos_choice], outputs=pos_output)
|
136 |
pos_examples = gr.Examples(examples = ner_example, inputs = [pos_input, pos_choice], outputs=pos_output, fn=pos)
|
137 |
|
|
|
140 |
with gr.Column():
|
141 |
with gr.Row():
|
142 |
with gr.Column():
|
143 |
+
ner_choice = gr.Radio(choices = ["turna_ner_wikiann", "turna_ner_milliyet"], label ="Model", value="turna_ner_wikiann")
|
144 |
ner_input = gr.Textbox(label="NER Input")
|
145 |
ner_submit = gr.Button()
|
146 |
ner_output = gr.Textbox(label="NER Output")
|
|
|
152 |
with gr.Column():
|
153 |
with gr.Row():
|
154 |
with gr.Column():
|
155 |
+
paraphrasing_choice = gr.Radio(choices = ["turna_paraphrasing_tatoeba", "turna_paraphrasing_opensubtitles"], label ="Model", value="turna_paraphrasing_tatoeba")
|
156 |
paraphrasing_input = gr.Textbox(label = "Paraphrasing Input")
|
157 |
paraphrasing_submit = gr.Button()
|
158 |
+
paraphrasing_output = gr.Text(label="Paraphrasing Output")
|
159 |
|
160 |
paraphrasing_submit.click(paraphrase, inputs=[paraphrasing_input, paraphrasing_choice], outputs=paraphrasing_output)
|
161 |
paraphrase_examples = gr.Examples(examples = long_text, inputs = [paraphrasing_input, paraphrasing_choice], outputs=paraphrasing_output, fn=paraphrase)
|
|
|
164 |
with gr.Column():
|
165 |
with gr.Row():
|
166 |
with gr.Column():
|
167 |
+
sum_choice = gr.Radio(choices = ["turna_summarization_mlsum", "turna_summarization_tr_news"], label ="Model", value="turna_summarization_mlsum")
|
168 |
sum_input = gr.Textbox(label = "Summarization Input")
|
169 |
sum_submit = gr.Button()
|
170 |
sum_output = gr.Textbox(label = "Summarization Output")
|