File size: 3,457 Bytes
f85031d
 
 
 
 
 
 
f044f58
f85031d
624765a
f85031d
 
 
 
 
 
 
 
624765a
5f26084
f85031d
 
 
6de91ce
4e4d74b
f85031d
 
624765a
237ad46
f85031d
 
106c2a5
f85031d
 
 
 
 
 
 
 
 
 
 
 
 
 
f38f30b
 
 
 
 
f85031d
f38f30b
 
 
 
 
 
 
 
fc91bcf
3e32458
fc91bcf
f85031d
 
691d9e6
f38f30b
3e32458
fc91bcf
1613f8b
f85031d
 
 
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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
import streamlit as st
from transformers import pipeline
import openai

# Turkish 
#sentiment_pipeline_tr = pipeline(task = "text-classification", model = "SoDehghan/BERTurk-hate-speech-detection")           # "gritli/bert-sentiment-analyses-imdb"
#sentiment_pipeline_tr_test = pipeline(task = "text-classification", model = "SoDehghan/test")            
strength_pipeline_tr  = pipeline(task = "text-classification", model = "SoDehghan/BERTurk-hate-speech-strength-prediction")


def write():
    st.markdown(
    """
    # Hate Speech Detection in Turkish
    
    """
    )

    
        
    def determine_hate_terms (chunk):
              response = openai.ChatCompletion.create(
              model= "gpt-3.5-turbo-1106",
              messages= [{"role":"system", "content":"This is a tool for detecting hate speech and preventing spread of them on social networks\n1. Please help us\n2. Use encoding=utf8"},
                         {"role": "user",  "content":f"determine which words in this text contain hateful sentiment:{chunk}"}])

              return (response['choices'][0]['message']['content'])

    
        
    tr_input = st.text_area("Enter your text here:", height=50, key="tr_input")  #height=30
    if st.button("Evaluate", key="tr_predict"):
       st.write(" ")
       with st.spinner('Generating predictions...'):
         #result_sentiment_tr = sentiment_pipeline_tr(tr_input)
         #sentiment_tr = result_sentiment_tr[0]["label"]
         #label_dict_sentiment = {'LABEL_1': 'Detection: Hate ❌', 'LABEL_0': 'Detection: Non-hate βœ…'}  
         #sentiment_tr = label_dict_sentiment[sentiment_tr]

         #result_sentiment_tr_test = sentiment_pipeline_tr_test(tr_input)
         #sentiment_tr_test = result_sentiment_tr_test[0]["label"]
         #label_dict_sentiment = {'LABEL_1': 'Detection: Hate ❌', 'LABEL_0': 'Detection: Non-hate βœ…'}  
         #sentiment_tr_test = label_dict_sentiment[sentiment_tr_test]  

         result_strength_tr = strength_pipeline_tr(tr_input)
         strength_tr = result_strength_tr[0]["label"]
         #label_dict_strength = {'LABEL_0': ' 0 (No hate speech)', 
                               # 'LABEL_1': ' 1 (Exaggeration/Generalization/Distortion)', 
                               # 'LABEL_2': ' 2 (Symbolization)',
                               # 'LABEL_3': ' 3 (Swearing/Insult/Humiliation)', 
                               # 'LABEL_4': ' 4 (Hostility/Attack/Threat of Injury)'}  

         label_dict_strength = {'LABEL_0': ' 0 ', 
                                'LABEL_1': ' 1 ', 
                                'LABEL_2': ' 2 ',
                                'LABEL_3': ' 3 ', 
                                'LABEL_4': ' 4 '}  
           
         label_dict_sentiment = {'LABEL_0': ' Non-hate βœ…', 'LABEL_1': ' Hate ❌', 'LABEL_2': ' Hate ❌', 'LABEL_3': ' Hate ❌', 'LABEL_4': ' Hate ❌'}
         
         openai.api_key = ''
         
         #hate_terms = determine_hate_terms(tr_input)
         sentiment_tr = label_dict_sentiment[strength_tr]
         strength_tr = label_dict_strength[strength_tr]
         st.write(f" **Binary Classification:** {sentiment_tr}")
         st.write(f" **Strength of Hate:** {strength_tr}")
         #st.write(' ')
         #st.write(f" **ChatGPT Prediction:** {hate_terms}")
         #st.write(hate_terms)
         #st.write(sentiment_tr_test)  
         #st.success(sentiment_tr)
         #st.success(strength_tr)