File size: 2,603 Bytes
30c7664
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
ffc2586
30c7664
 
 
8e85438
30c7664
0b70d48
 
29e454e
30c7664
 
8e85438
30c7664
 
 
 
 
 
 
 
 
 
8e85438
30c7664
e41b98a
4f7fb4d
29e454e
30c7664
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59

import streamlit as st
import requests
import time 
from transformers import pipeline
import os


# Set the page configuration
st.set_page_config(
        page_title="Hate Speech Detection",
        page_icon="📖",  #":bar_chart:"
        layout='centered'
    )

#title = r"$\textsf{\small Hate Speech Detection}$"
#st.title(title)
#st.write("In this HuggingFace space you will be able to use our Hate Speech Detection model built at [VERİM - Center of Excellence in Data Analytics - Sabanci University](https://github.com/verimsu).")


# Turkish 
sentiment_pipeline_tr = pipeline(task = "text-classification", model = "SoDehghan/BERTurk-hate-speech")  # "gritli/bert-sentiment-analyses-imdb"
header_tr = r"$\textsf{\scriptsize HSD in Turkish}$"
st.subheader(header_tr)

tr_input = st.text_area("Enter your text here:", height=50, key="tr_input")  #height=30
if st.button("Click for predictions!", key="tr_predict"):
    st.write(" ")
    with st.spinner('Generating predictions...'):
        result_tr = sentiment_pipeline_tr(tr_input)
        sentiment_tr = result_tr[0]["label"]
        label_dict = {'LABEL_1': 'Hate ❌  ', 'LABEL_0': 'Non-hate ✅  '}  #🚫
        sentiment_tr = label_dict[sentiment_tr]

        strength_tr = " "
        st.write(f"Detection: {sentiment_tr},  Strength: {strength_tr}")


st.write("  ")
# Arabic
sentiment_pipeline_ar = pipeline(task = "text-classification", model = "SoDehghan/BERTurk-hate-speech")
header_ar = r"$\textsf{\scriptsize HSD in Arabic}$"
st.subheader(header_ar)

ar_input = st.text_area("Enter your text here:", height=50 , key="ar_input")
if st.button("Click for predictions!", key="ar_predict"):
    with st.spinner('Generating predictions...'):
        result_ar = sentiment_pipeline_ar(ar_input)
        sentiment_ar = result_ar[0]["label"]
        label_dict = {'LABEL_1': 'Hate ❌  ', 'LABEL_0': 'Non-hate ✅  '}
        sentiment_ar = label_dict[sentiment_ar]

        strength_ar = " "
        st.write(f"Detection: {sentiment_ar},  Strength: {strength_ar}") 


st.sidebar.title("Hate Speech Detection")
#st.sidebar.write("In this HuggingFace space you can use Hate Speech Detection model built at [VERİM - Center of Excellence in Data Analytics - Sabanci University](https://github.com/verimsu).")
st.sidebar.write('This tool is developed in the context of the EU project "Utilizing Digital Technology for Social Cohesion, Positive Messaging and Peace by Boosting Collaboration, Exchange and Solidarity" (EuropeAid/170389/DD/ACT/Multi) by [Sabanci University Center of Excellence in Data Analytics](https://github.com/verimsu).')