Spaces:
Sleeping
Sleeping
Create app.py
Browse files
app.py
ADDED
@@ -0,0 +1,77 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
|
2 |
+
import gradio as gr
|
3 |
+
import spaces
|
4 |
+
from transformers import pipeline
|
5 |
+
import torch
|
6 |
+
|
7 |
+
binary_example = [["Yahudi terörüne karşı protestolar kararlılıkla devam ediyor."]]
|
8 |
+
category_example = [["Ermeni zulmü sırasında hayatını kaybeden kadınlar anısına dikilen anıt ziyarete açıldı."]]
|
9 |
+
target_example = [["Dün 5 bin suriyeli enik doğmuştur zaten Türkiyede aq 5 bin suriyelinin gitmesi çok çok az"]]
|
10 |
+
|
11 |
+
DESCRIPTION = """"
|
12 |
+
## Hate Speech Detection in Turkish News
|
13 |
+
"""
|
14 |
+
|
15 |
+
CITATION = """"
|
16 |
+
"""
|
17 |
+
|
18 |
+
def binary_classification(input):
|
19 |
+
model = pipeline(model='gokceuludogan/berturk_tr_hate_print_w0.1')
|
20 |
+
return model(input)[0]
|
21 |
+
|
22 |
+
def category_classification():
|
23 |
+
model = pipeline(model='gokceuludogan/berturk/tr_hateprint_cat_w0.1_b128')
|
24 |
+
return model(input)[0]
|
25 |
+
|
26 |
+
def target_detection():
|
27 |
+
model = pipeline(model='gokceuludogan/turna_generation_tr_hateprint_target')
|
28 |
+
return model(input)[0]
|
29 |
+
|
30 |
+
with gr.Blocks(theme="abidlabs/Lime") as demo:
|
31 |
+
|
32 |
+
#gr.Markdown("# TURNA")
|
33 |
+
#gr.Image("images/turna-logo.png", width=100, show_label=False, show_download_button=False, show_share_button=False)
|
34 |
+
|
35 |
+
with gr.Tab("TRHatePrint"):
|
36 |
+
gr.Markdown(DESCRIPTION)
|
37 |
+
|
38 |
+
with gr.Tab("Binary Classification"):
|
39 |
+
gr.Markdown("Enter text to analyse hatefulness and pick the model.")
|
40 |
+
with gr.Column():
|
41 |
+
with gr.Row():
|
42 |
+
with gr.Column():
|
43 |
+
# sentiment_choice = gr.Radio(choices = ["turna_", "berturk"], label ="Model", value="turna_")
|
44 |
+
sentiment_input = gr.Textbox(label="Input")
|
45 |
+
|
46 |
+
sentiment_submit = gr.Button()
|
47 |
+
sentiment_output = gr.Textbox(label="Output")
|
48 |
+
sentiment_submit.click(binary_classification, inputs=[sentiment_input], outputs=sentiment_output)
|
49 |
+
sentiment_examples = gr.Examples(examples = binary_example, inputs = [sentiment_input], outputs=sentiment_output, fn=binary_classification)
|
50 |
+
|
51 |
+
with gr.Tab("Hate Speech Categorization"):
|
52 |
+
gr.Markdown("Enter a hateful text to categorize or try the example.")
|
53 |
+
with gr.Column():
|
54 |
+
with gr.Row():
|
55 |
+
with gr.Column():
|
56 |
+
text_input = gr.Textbox(label="Input")
|
57 |
+
|
58 |
+
text_submit = gr.Button()
|
59 |
+
text_output = gr.Textbox(label="Output")
|
60 |
+
text_submit.click(category_classification, inputs=[text_input], outputs=text_output)
|
61 |
+
text_examples = gr.Examples(examples = category_example,inputs=[text_input], outputs=text_output, fn=category_classification)
|
62 |
+
|
63 |
+
|
64 |
+
with gr.Tab("Target Detection"):
|
65 |
+
gr.Markdown("Enter text to detect targets ")
|
66 |
+
with gr.Column():
|
67 |
+
with gr.Row():
|
68 |
+
with gr.Column():
|
69 |
+
nli_first_input = gr.Textbox(label="Input")
|
70 |
+
nli_submit = gr.Button()
|
71 |
+
nli_output = gr.Textbox(label="Output")
|
72 |
+
nli_submit.click(target_detection, inputs=[nli_first_input], outputs=nli_output)
|
73 |
+
nli_examples = gr.Examples(examples = target_example, inputs = [nli_first_input], outputs=nli_output, fn=target_example)
|
74 |
+
|
75 |
+
gr.Markdown(CITATION)
|
76 |
+
|
77 |
+
demo.launch()
|