Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -2,8 +2,41 @@ from simpletransformers.classification import ClassificationModel
|
|
| 2 |
import gradio as gr
|
| 3 |
import pandas as pd
|
| 4 |
import numpy as np
|
|
|
|
|
|
|
|
|
|
|
|
|
| 5 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 6 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 7 |
|
| 8 |
def predict(text):
|
| 9 |
model_path = "bert_model"
|
|
|
|
| 2 |
import gradio as gr
|
| 3 |
import pandas as pd
|
| 4 |
import numpy as np
|
| 5 |
+
import nltk
|
| 6 |
+
from nltk.corpus import stopwords
|
| 7 |
+
import re
|
| 8 |
+
import string
|
| 9 |
|
| 10 |
+
# NLTK kütüphanesini kullanarak türkçe dilindeki etkisiz kelimeleri (stopwords) indiriyoruz.
|
| 11 |
+
nltk.download('stopwords')
|
| 12 |
+
# İndirilen etkisiz kelimeleri "stop_words_list" değişkenine atıyoruz.
|
| 13 |
+
stop_words_list = stopwords.words('turkish')
|
| 14 |
+
# Veri setindeki "text" sütunu altındaki hatalı alanları temizlemek için bir dizi oluşturduk.
|
| 15 |
+
false_text = ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z']
|
| 16 |
|
| 17 |
+
def preprocess_text(text):
|
| 18 |
+
# Küçük harflere çevirme
|
| 19 |
+
text = text.lower()
|
| 20 |
+
# Satır sonu karakterlerini kaldırma
|
| 21 |
+
import re
|
| 22 |
+
text = re.sub(r'\n', ' ', text)
|
| 23 |
+
# Rakamları kaldırma
|
| 24 |
+
text = re.sub(r'\d', '', text)
|
| 25 |
+
# Noktalama işaretlerini kaldırma
|
| 26 |
+
import string
|
| 27 |
+
text = text.translate(str.maketrans("", "", string.punctuation))
|
| 28 |
+
# Stop-words'leri kaldırma
|
| 29 |
+
words = text.split()
|
| 30 |
+
words = [word for word in words if not word in stop_words_list]
|
| 31 |
+
# Veri setindeki hatalı verilerin kaldırılması
|
| 32 |
+
words = [word for word in words if not word in false_text]
|
| 33 |
+
# Tekrarlanan karakterlerin kaldırılması
|
| 34 |
+
words = [re.sub(r'(.)\1{1,}', r'\1\1', word) for word in words]
|
| 35 |
+
# Tekrarlanan boşlukların kaldırılması
|
| 36 |
+
words = [word.strip() for word in words if len(word.strip()) > 1]
|
| 37 |
+
|
| 38 |
+
text = " ".join(words)
|
| 39 |
+
return text
|
| 40 |
|
| 41 |
def predict(text):
|
| 42 |
model_path = "bert_model"
|