NimaKL commited on
Commit
ca9de3e
·
1 Parent(s): 40f05a9

Upload 2 files

Browse files
Files changed (2) hide show
  1. app.py +75 -0
  2. requirements.txt +6 -0
app.py ADDED
@@ -0,0 +1,75 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import pandas as pd
2
+ import numpy as np
3
+ import tensorflow as tf
4
+ from transformers.models.bert import BertTokenizer
5
+ from transformers import TFBertModel
6
+ import streamlit as st
7
+ import pandas as pd
8
+ from transformers import TFAutoModel
9
+
10
+
11
+ hist_loss= [0.1971,0.0732,0.0465,0.0319,0.0232,0.0167,0.0127,0.0094,0.0073,0.0058,0.0049,0.0042]
12
+ hist_acc = [0.9508,0.9811,0.9878,0.9914,0.9936,0.9954,0.9965,0.9973,0.9978,0.9983,0.9986,0.9988]
13
+ hist_val_acc = [0.9804,0.9891,0.9927,0.9956,0.9981,0.998,0.9991,0.9997,0.9991,0.9998,0.9998,0.9998]
14
+ hist_val_loss = [0.0759,0.0454,0.028,0.015,0.0063,0.0064,0.004,0.0011,0.0021,0.00064548,0.0010,0.00042896]
15
+ Epochs = [i for i in range(1,13)]
16
+
17
+ hist_loss[:] = [x * 100 for x in hist_loss]
18
+ hist_acc[:] = [x * 100 for x in hist_acc]
19
+ hist_val_acc[:] = [x * 100 for x in hist_val_acc]
20
+ hist_val_loss[:] = [x * 100 for x in hist_val_loss]
21
+ d = {'val_acc':hist_val_acc, 'acc':hist_acc,'loss':hist_loss, 'val_loss':hist_val_loss, 'Epochs': Epochs}
22
+ chart_data = pd.DataFrame(d)
23
+ chart_data.index = range(1,13)
24
+
25
+ @st.cache(suppress_st_warning=True, allow_output_mutation=True)
26
+ def load_model(show_spinner=True):
27
+ yorum_model = TFAutoModel.from_pretrained("NimaKL/TC32")
28
+ tokenizer = BertTokenizer.from_pretrained('dbmdz/bert-base-turkish-128k-uncased')
29
+ return yorum_model, tokenizer
30
+
31
+ st.set_page_config(layout='wide', initial_sidebar_state='expanded')
32
+ col1, col2= st.columns(2)
33
+ with col1:
34
+ st.title("TC32 Multi-Class Text Classification")
35
+ st.subheader('Model Loss and Accuracy')
36
+ st.area_chart(chart_data, x = 'Epochs')
37
+ yorum_model, tokenizer = load_model()
38
+
39
+
40
+
41
+ with col2:
42
+ st.title("Sınıfı bulmak için bir şikayet girin.")
43
+ st.subheader("Şikayet")
44
+ text = st.text_area('',"Jandarma Genel Komutanlığı Alo 156 'yı Aradığımda Yardımcı Olunmadı!",label_visibility ='collapsed', height=240)
45
+ aButton = st.button('Ara')
46
+
47
+ def prepare_data(input_text, tokenizer):
48
+ token = tokenizer.encode_plus(
49
+ input_text,
50
+ max_length=256,
51
+ truncation=True,
52
+ padding='max_length',
53
+ add_special_tokens=True,
54
+ return_tensors='tf'
55
+ )
56
+ return {
57
+ 'input_ids': tf.cast(token.input_ids, tf.float64),
58
+ 'attention_mask': tf.cast(token.attention_mask, tf.float64)
59
+ }
60
+
61
+ def make_prediction(model, processed_data, classes=['Alışveriş','Anne-Bebek','Beyaz Eşya','Bilgisayar','Cep Telefonu','Eğitim','Elektronik','Emlak ve İnşaat','Enerji','Etkinlik ve Organizasyon','Finans','Gıda','Giyim','Hizmet','İçecek','İnternet','Kamu','Kargo-Nakliyat','Kozmetik','Küçük Ev Aletleri','Medya','Mekan ve Eğlence','Mobilya - Ev Tekstili','Mücevher Saat Gözlük','Mutfak Araç Gereç','Otomotiv','Sağlık','Sigorta','Spor','Temizlik','Turizm','Ulaşım']):
62
+ probs = model.predict(processed_data)[0]
63
+ return classes[np.argmax(probs)]
64
+
65
+
66
+ if text or aButton:
67
+ with col2:
68
+ with st.spinner('Wait for it...'):
69
+ processed_data = prepare_data(text, tokenizer)
70
+ result = make_prediction(yorum_model, processed_data=processed_data)
71
+ description = '<table style="border: collapse;"><tr><div style="height: 62px;"></div></tr><tr><p style="border-width: medium; border-color: #aa5e70; border-radius: 10px;padding-top: 1px;padding-left: 20px;background:#20212a;font-family:Courier New; color: white;font-size: 36px; font-weight: boldest;">'+result+'</p></tr><table>'
72
+ st.markdown(description, unsafe_allow_html=True)
73
+ with col1:
74
+ st.success("Tahmin başarıyla tamamlandı!")
75
+
requirements.txt ADDED
@@ -0,0 +1,6 @@
 
 
 
 
 
 
 
1
+ numpy==1.23.4
2
+ tensorflow==2.10.0
3
+ transformers==4.23.1
4
+ pandas==1.5.1
5
+ streamlit==1.14.0
6
+