Gulzd commited on
Commit
92d8d31
·
1 Parent(s): 3d09792

update app.py

Browse files
Files changed (1) hide show
  1. app.py +13 -48
app.py CHANGED
@@ -1,49 +1,15 @@
 
 
1
  import pandas as pd
2
  import numpy as np
3
- import matplotlib.pyplot as plt
4
- from collections import Counter
5
- import nltk
6
- from nltk.corpus import stopwords
7
- import re
8
- import string
9
- import gradio as gr
10
-
11
-
12
- nltk.download('stopwords')
13
- stop_words_list = stopwords.words('turkish')
14
- 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']
15
 
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
-
42
- def predict(texts):
43
- model_path = "bert_model"
44
  model = ClassificationModel('bert', model_path, use_cuda=False)
45
- predictions, _ = model.predict(texts)
46
- return [result_predict(prediction) for prediction in predictions]
47
 
48
  def result_predict(num):
49
  if num == 4:
@@ -57,16 +23,15 @@ def result_predict(num):
57
  elif num == 2:
58
  return 'SEXIST'
59
 
60
-
61
-
62
- # Gradio Interface oluşturun
63
  iface = gr.Interface(
64
- fn=predict,
65
- inputs="text",
66
- outputs=["text", "text"],
67
  live=True,
68
- layout="horizontal",
69
- title="BERT Text Classification"
70
  )
71
 
 
72
  iface.launch()
 
1
+ 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 = "/content/drive/MyDrive/bert_model"
 
 
 
 
10
  model = ClassificationModel('bert', model_path, use_cuda=False)
11
+ prediction, _ = model.predict([text])
12
+ return result_predict(prediction[0])
13
 
14
  def result_predict(num):
15
  if num == 4:
 
23
  elif num == 2:
24
  return 'SEXIST'
25
 
26
+ # Gradio arayüzünü oluştur
 
 
27
  iface = gr.Interface(
28
+ fn=predict, # Kullanıcıdan alınan metni modelinize ileten fonksiyon
29
+ inputs=gr.Textbox(), # Kullanıcıdan metin girişi alın
30
+ outputs=gr.Textbox(), # Model çıktısını görüntülemek için metin kutusu
31
  live=True,
32
+ title='Yorum Tespiti',
33
+ css='''span{text-transform: uppercase} p{text-align: center}'''
34
  )
35
 
36
+ # Gradio arayüzünü başlat
37
  iface.launch()