kmkarakaya commited on
Commit
0f09c6c
1 Parent(s): 172f681

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +40 -0
app.py ADDED
@@ -0,0 +1,40 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import tensorflow as tf
2
+ import numpy as np
3
+ import pickle
4
+ import string
5
+ import gradio as gr
6
+
7
+ @tf.keras.utils.register_keras_serializable()
8
+ def custom_standardization(input_string):
9
+ """ Remove html line-break tags and handle punctuation """
10
+ no_uppercased = tf.strings.lower(input_string, encoding='utf-8')
11
+ no_stars = tf.strings.regex_replace(no_uppercased, "\*", " ")
12
+ no_repeats = tf.strings.regex_replace(no_stars, "devamını oku", "")
13
+ no_html = tf.strings.regex_replace(no_repeats, "", "")
14
+ no_digits = tf.strings.regex_replace(no_html, "\w*\d\w*","")
15
+ no_punctuations = tf.strings.regex_replace(no_digits, f"([{string.punctuation}])", r" ")
16
+ #remove stop words
17
+ #no_stop_words = ' '+no_punctuations+ ' '
18
+ #for each in tr_stop_words.values:
19
+ # no_stop_words = tf.strings.regex_replace(no_stop_words, ' '+each[0]+' ' , r" ")
20
+ no_extra_space = tf.strings.regex_replace(no_punctuations, " +"," ")
21
+ #remove Turkish chars
22
+ no_I = tf.strings.regex_replace(no_extra_space, "ı","i")
23
+ no_O = tf.strings.regex_replace(no_I, "ö","o")
24
+ no_C = tf.strings.regex_replace(no_O, "ç","c")
25
+ no_S = tf.strings.regex_replace(no_C, "ş","s")
26
+ no_G = tf.strings.regex_replace(no_S, "ğ","g")
27
+ no_U = tf.strings.regex_replace(no_G, "ü","u")
28
+ return no_U
29
+
30
+ end_to_end_model=tf.keras.models.load_model('MCTC_Conv1D_E2E')
31
+
32
+ with open('id_to_category.pkl', 'rb') as fp:
33
+ id_to_category = pickle.load(fp)
34
+
35
+ def text_classifier(text):
36
+ predictions=end_to_end_model.predict(examples)
37
+ for pred in predictions:
38
+ return(id_to_category[np.argmax(pred)])
39
+
40
+ iface= gr.Interface(fn=text_classifier, inputs="text", outputs="text").launch()