Spaces:
Sleeping
Sleeping
| 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) | |
| 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() |