TRHatePrint / app.py
gokceuludogan's picture
Update app.py
8b6ab08 verified
raw
history blame
4.35 kB
import gradio as gr
import spaces
from transformers import pipeline
import torch
import os
token = os.getenv('HF_AUTH_TOKEN')
print(token)
binary_example = [["Yahudi terörüne karşı protestolar kararlılıkla devam ediyor."]]
category_example = [["Ermeni zulmü sırasında hayatını kaybeden kadınlar anısına dikilen anıt ziyarete açıldı."]]
target_example = [["Dün 5 bin suriyeli enik doğmuştur zaten Türkiyede aq 5 bin suriyelinin gitmesi çok çok az"]]
DESCRIPTION = """"
## Hate Speech Detection in Turkish News
"""
CITATION = """"
"""
def binary_classification(input, choice):
model = pipeline(model=f'gokceuludogan/{choice}')
return model(input)[0]
def category_classification(input, choice):
model = pipeline(model=f'gokceuludogan/{choice}')
return model(input)[0]
def target_detection(input):
model = pipeline(model='gokceuludogan/turna_generation_tr_hateprint_target')
return model(input)[0]['generated_text']
def multi_detection(input):
model = pipeline(model='gokceuludogan/turna_generation_tr_hateprint_multi')
return model(input)[0]['generated_text']
with gr.Blocks(theme="abidlabs/Lime") as demo:
#gr.Markdown("# TURNA")
#gr.Image("images/turna-logo.png", width=100, show_label=False, show_download_button=False, show_share_button=False)
with gr.Tab("TRHatePrint"):
gr.Markdown(DESCRIPTION)
with gr.Tab("Binary Classification"):
gr.Markdown("Enter text to analyse hatefulness and pick the model.")
with gr.Column():
with gr.Row():
with gr.Column():
sentiment_choice = gr.Radio(choices = ["turna_tr_hateprint", "turna_tr_hateprint_5e6_w0.1_", "berturk_tr_hateprint_w0.1", "berturk_tr_hateprint_w0.1_b128"], label ="Model", value="turna_tr_hateprint")
sentiment_input = gr.Textbox(label="Input")
sentiment_submit = gr.Button()
sentiment_output = gr.Textbox(label="Output")
sentiment_submit.click(binary_classification, inputs=[sentiment_input, sentiment_choice], outputs=sentiment_output)
sentiment_examples = gr.Examples(examples = binary_example, inputs = [sentiment_input, sentiment_choice], outputs=sentiment_output, fn=binary_classification)
with gr.Tab("Hate Speech Categorization"):
gr.Markdown("Enter a hateful text to categorize or try the example.")
with gr.Column():
with gr.Row():
with gr.Column():
text_choice = gr.Radio(choices= ["berturk_tr_hateprint_cat_w0.1_b128", "berturk_tr_hateprint_cat_w0.1"])
text_input = gr.Textbox(label="Input")
text_submit = gr.Button()
text_output = gr.Textbox(label="Output")
text_submit.click(category_classification, inputs=[text_input, text_choice], outputs=text_output)
text_examples = gr.Examples(examples = category_example,inputs=[text_input, text_choice], outputs=text_output, fn=category_classification)
with gr.Tab("Target Detection"):
gr.Markdown("Enter text to detect targets ")
with gr.Column():
with gr.Row():
with gr.Column():
nli_first_input = gr.Textbox(label="Input")
nli_submit = gr.Button()
nli_output = gr.Textbox(label="Output")
nli_submit.click(target_detection, inputs=[nli_first_input], outputs=nli_output)
nli_examples = gr.Examples(examples = target_example, inputs = [nli_first_input], outputs=nli_output, fn=target_detection)
with gr.Tab("Multi Detection"):
gr.Markdown("Enter text to detect hate, category, and targets ")
with gr.Column():
with gr.Row():
with gr.Column():
nli_first_input = gr.Textbox(label="Input")
nli_submit = gr.Button()
nli_output = gr.Textbox(label="Output")
nli_submit.click(multi_detection, inputs=[nli_first_input], outputs=nli_output)
nli_examples = gr.Examples(examples = target_example, inputs = [nli_first_input], outputs=nli_output, fn=multi_detection)
gr.Markdown(CITATION)
demo.launch()