File size: 2,220 Bytes
8fbdf27
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
import pandas as pd
import numpy as np
import tensorflow as tf
import string
import re
import gradio as gr

tr_stop_words = pd.read_csv("tr-stop-words.txt",header=None)

@tf.keras.utils.register_keras_serializable()
def standart_custom(input_text):
    lower = tf.strings.lower(input_text, encoding='utf-8') 
    no_stars = tf.strings.regex_replace(lower, "\*", " ")
    stripped_html = tf.strings.regex_replace(no_stars, "<br />", "") 
    no_numbers = tf.strings.regex_replace(stripped_html, "\w*\d\w*","") 
    no_punctuation = tf.strings.regex_replace(no_numbers,'[%s]' % re.escape(string.punctuation),'') 
    #remove stopwords
    no_stop_words =' '+no_punctuation+ ' '
    for each in tr_stop_words.values:
        no_stop_words = tf.strings.regex_replace(no_stop_words, ' '+each[0]+' ', r" ")
    no_space = tf.strings.regex_replace(no_stop_words, " +", " ")
    no_turkish_character = tf.strings.regex_replace(no_space, "ç", "c") 
    no_turkish_character = tf.strings.regex_replace(no_turkish_character, "ğ", "g")
    no_turkish_character = tf.strings.regex_replace(no_turkish_character, "ı", "i")
    no_turkish_character = tf.strings.regex_replace(no_turkish_character, "ö", "o")
    no_turkish_character = tf.strings.regex_replace(no_turkish_character, "ş", "s")
    no_turkish_character = tf.strings.regex_replace(no_turkish_character, "ü", "u")
    return no_turkish_character   

loaded_end_to_end_model = tf.keras.models.load_model("end_to_end_model")

def gradio_comment(comment):
    
   
    result = loaded_end_to_end_model.predict([comment])
    result  = np.round(result,1)
    result = (result > 0.5).astype(int)
    if result[0][0] == 1:

      if result[0][1] == 1:
        text = "OFFENSİVE/INSULT"
      elif result[0][3] == 1:
        text = 'OFFENSİVE/SEXIST'
      elif result[0][4] == 1:
        text = 'OFFENSİVE/RACIST'
      elif result[0][5] == 1:
        text = 'OFFENSİVE/PROFANITY'
    else:
      text = "NOT OFFENSİVE/OTHER"
    

    return text

GradioGUI = gr.Interface(
    fn=gradio_comment,
    inputs='text',
    outputs='text',
    title='Aşağılayıcı Yorum Tespiti',
    css='''span{text-transform: uppercase} p{text-align: center}''')

GradioGUI.launch()