TRHatePrint / app.py
gokceuludogan's picture
Update app.py
e6fc8aa verified
raw
history blame
3.32 kB
import gradio as gr
import spaces
from transformers import pipeline
import torch
ımport os
token = os.getenv('HF_AUTH_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):
model = pipeline(model='gokceuludogan/berturk_tr_hate_print_w0.1', token=token)
return model(input)[0]
def category_classification():
model = pipeline(model='gokceuludogan/berturk/tr_hateprint_cat_w0.1_b128', token=token)
return model(input)[0]
def target_detection():
model = pipeline(model='gokceuludogan/turna_generation_tr_hateprint_target', token=token)
return model(input)[0]
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_", "berturk"], label ="Model", value="turna_")
sentiment_input = gr.Textbox(label="Input")
sentiment_submit = gr.Button()
sentiment_output = gr.Textbox(label="Output")
sentiment_submit.click(binary_classification, inputs=[sentiment_input], outputs=sentiment_output)
sentiment_examples = gr.Examples(examples = binary_example, inputs = [sentiment_input], 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_input = gr.Textbox(label="Input")
text_submit = gr.Button()
text_output = gr.Textbox(label="Output")
text_submit.click(category_classification, inputs=[text_input], outputs=text_output)
text_examples = gr.Examples(examples = category_example,inputs=[text_input], 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_example)
gr.Markdown(CITATION)
demo.launch()