Create app.py
Browse files
app.py
ADDED
|
@@ -0,0 +1,61 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import pandas as pd
|
| 2 |
+
import numpy as np
|
| 3 |
+
import tensorflow as tf
|
| 4 |
+
import string
|
| 5 |
+
import re
|
| 6 |
+
import gradio as gr
|
| 7 |
+
|
| 8 |
+
tr_stop_words = pd.read_csv("tr-stop-words.txt",header=None)
|
| 9 |
+
|
| 10 |
+
@tf.keras.utils.register_keras_serializable()
|
| 11 |
+
def standart_custom(input_text):
|
| 12 |
+
lower = tf.strings.lower(input_text, encoding='utf-8')
|
| 13 |
+
no_stars = tf.strings.regex_replace(lower, "\*", " ")
|
| 14 |
+
stripped_html = tf.strings.regex_replace(no_stars, "<br />", "")
|
| 15 |
+
no_numbers = tf.strings.regex_replace(stripped_html, "\w*\d\w*","")
|
| 16 |
+
no_punctuation = tf.strings.regex_replace(no_numbers,'[%s]' % re.escape(string.punctuation),'')
|
| 17 |
+
#remove stopwords
|
| 18 |
+
no_stop_words =' '+no_punctuation+ ' '
|
| 19 |
+
for each in tr_stop_words.values:
|
| 20 |
+
no_stop_words = tf.strings.regex_replace(no_stop_words, ' '+each[0]+' ', r" ")
|
| 21 |
+
no_space = tf.strings.regex_replace(no_stop_words, " +", " ")
|
| 22 |
+
no_turkish_character = tf.strings.regex_replace(no_space, "ç", "c")
|
| 23 |
+
no_turkish_character = tf.strings.regex_replace(no_turkish_character, "ğ", "g")
|
| 24 |
+
no_turkish_character = tf.strings.regex_replace(no_turkish_character, "ı", "i")
|
| 25 |
+
no_turkish_character = tf.strings.regex_replace(no_turkish_character, "ö", "o")
|
| 26 |
+
no_turkish_character = tf.strings.regex_replace(no_turkish_character, "ş", "s")
|
| 27 |
+
no_turkish_character = tf.strings.regex_replace(no_turkish_character, "ü", "u")
|
| 28 |
+
return no_turkish_character
|
| 29 |
+
|
| 30 |
+
loaded_end_to_end_model = tf.keras.models.load_model("end_to_end_model")
|
| 31 |
+
|
| 32 |
+
def gradio_comment(comment):
|
| 33 |
+
|
| 34 |
+
|
| 35 |
+
result = loaded_end_to_end_model.predict([comment])
|
| 36 |
+
result = np.round(result,1)
|
| 37 |
+
result = (result > 0.5).astype(int)
|
| 38 |
+
if result[0][0] == 1:
|
| 39 |
+
|
| 40 |
+
if result[0][1] == 1:
|
| 41 |
+
text = "OFFENSİVE/INSULT"
|
| 42 |
+
elif result[0][3] == 1:
|
| 43 |
+
text = 'OFFENSİVE/SEXIST'
|
| 44 |
+
elif result[0][4] == 1:
|
| 45 |
+
text = 'OFFENSİVE/RACIST'
|
| 46 |
+
elif result[0][5] == 1:
|
| 47 |
+
text = 'OFFENSİVE/PROFANITY'
|
| 48 |
+
else:
|
| 49 |
+
text = "NOT OFFENSİVE/OTHER"
|
| 50 |
+
|
| 51 |
+
|
| 52 |
+
return text
|
| 53 |
+
|
| 54 |
+
GradioGUI = gr.Interface(
|
| 55 |
+
fn=gradio_comment,
|
| 56 |
+
inputs='text',
|
| 57 |
+
outputs='text',
|
| 58 |
+
title='Aşağılayıcı Yorum Tespiti',
|
| 59 |
+
css='''span{text-transform: uppercase} p{text-align: center}''')
|
| 60 |
+
|
| 61 |
+
GradioGUI.launch()
|