Spaces:
Runtime error
Runtime error
kmkarakaya
commited on
Commit
•
c3c7b98
1
Parent(s):
7da608d
Create app.py
Browse files
app.py
ADDED
@@ -0,0 +1,45 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import numpy as np
|
2 |
+
import tensorflow as tf
|
3 |
+
import pickle
|
4 |
+
import string
|
5 |
+
import pandas as pd
|
6 |
+
import gradio as gr
|
7 |
+
|
8 |
+
tr_stop_words = pd.read_csv('tr_stop_word.txt',header=None)
|
9 |
+
|
10 |
+
@tf.keras.utils.register_keras_serializable()
|
11 |
+
def custom_standardization(input_string):
|
12 |
+
""" Remove html line-break tags and handle punctuation """
|
13 |
+
no_uppercased = tf.strings.lower(input_string, encoding='utf-8')
|
14 |
+
no_stars = tf.strings.regex_replace(no_uppercased, "\*", " ")
|
15 |
+
no_repeats = tf.strings.regex_replace(no_stars, "devamını oku", "")
|
16 |
+
no_html = tf.strings.regex_replace(no_repeats, "<br />", "")
|
17 |
+
no_digits = tf.strings.regex_replace(no_html, "\w*\d\w*","")
|
18 |
+
no_punctuations = tf.strings.regex_replace(no_digits, f"([{string.punctuation}])", r" ")
|
19 |
+
#remove stop words
|
20 |
+
no_stop_words = ' '+no_punctuations+ ' '
|
21 |
+
for each in tr_stop_words.values:
|
22 |
+
no_stop_words = tf.strings.regex_replace(no_stop_words, ' '+each[0]+' ' , r" ")
|
23 |
+
no_extra_space = tf.strings.regex_replace(no_stop_words, " +"," ")
|
24 |
+
#remove Turkish chars
|
25 |
+
no_I = tf.strings.regex_replace(no_extra_space, "ı","i")
|
26 |
+
no_O = tf.strings.regex_replace(no_I, "ö","o")
|
27 |
+
no_C = tf.strings.regex_replace(no_O, "ç","c")
|
28 |
+
no_S = tf.strings.regex_replace(no_C, "ş","s")
|
29 |
+
no_G = tf.strings.regex_replace(no_S, "ğ","g")
|
30 |
+
no_U = tf.strings.regex_replace(no_G, "ü","u")
|
31 |
+
|
32 |
+
return no_U
|
33 |
+
loaded_end_to_end_model = tf.keras.models.load_model(path+"end_to_end_model")
|
34 |
+
pkl_file = open(path+"id_to_category.pkl", "rb")
|
35 |
+
id_to_category = pickle.load(pkl_file)
|
36 |
+
|
37 |
+
def classify (text):
|
38 |
+
pred=loaded_end_to_end_model.predict([text])
|
39 |
+
return id_to_category[np.argmax(pred)]
|
40 |
+
|
41 |
+
examples=['Dün aldığım samsung telefon bugün şarj tutmuyor',
|
42 |
+
'THY Uçak biletimi değiştirmek için başvurdum. Kimse geri dönüş yapmadı!']
|
43 |
+
|
44 |
+
iface = gr.Interface(fn=classify, inputs="text", outputs="text", examples=examples)
|
45 |
+
iface.launch()
|