kkAsmaa commited on
Commit
274b868
·
verified ·
1 Parent(s): 60f592c

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +7 -2
app.py CHANGED
@@ -4,7 +4,7 @@ import os
4
  import torch
5
  from transformers import BertTokenizer, AutoModelForSequenceClassification
6
 
7
- # acronym معالج التنظيف الرسمي لـ AraBERT الخاص بكِ
8
  from arabert.preprocess import ArabertPreprocessor
9
 
10
  # معرفات المستودع والمسار الفرعي لأسماء
@@ -48,9 +48,11 @@ def predict_safety_api(text):
48
  """
49
  cleaned_text = full_preprocess(text)
50
 
 
51
  full_encodings = tokenizer(cleaned_text, add_special_tokens=False, return_attention_mask=False)
52
  input_ids = full_encodings['input_ids']
53
 
 
54
  window_size = 60
55
  overlap = 20
56
  windows = []
@@ -68,6 +70,7 @@ def predict_safety_api(text):
68
  highest_unsafe_prob = 0.0
69
 
70
  for win_ids in windows:
 
71
  window_text = tokenizer.decode(win_ids, skip_special_tokens=True)
72
 
73
  inputs = tokenizer(
@@ -82,7 +85,9 @@ def predict_safety_api(text):
82
  outputs = model(**inputs)
83
 
84
  probs = torch.softmax(outputs.logits, dim=-1).flatten().tolist()
85
- unsafe_p = float(probs)
 
 
86
 
87
  if unsafe_p > 0.50:
88
  is_blocked = True
 
4
  import torch
5
  from transformers import BertTokenizer, AutoModelForSequenceClassification
6
 
7
+ # استدعاء معالج التنظيف الرسمي لـ AraBERT الخاص بكِ
8
  from arabert.preprocess import ArabertPreprocessor
9
 
10
  # معرفات المستودع والمسار الفرعي لأسماء
 
48
  """
49
  cleaned_text = full_preprocess(text)
50
 
51
+ # 1. تقطيع النص الأولي لأرقام مجهولة الأبعاد بدون حشو مسبق
52
  full_encodings = tokenizer(cleaned_text, add_special_tokens=False, return_attention_mask=False)
53
  input_ids = full_encodings['input_ids']
54
 
55
+ # تثبيت أبعاد النوافذ الذكية الخاصة بكِ (60/20)
56
  window_size = 60
57
  overlap = 20
58
  windows = []
 
70
  highest_unsafe_prob = 0.0
71
 
72
  for win_ids in windows:
73
+ # تحويل الأرقام الفرعية للنافذة الحالية إلى نص مجدداً ليمررها التوكنايزر بطريقتكِ الذكية
74
  window_text = tokenizer.decode(win_ids, skip_special_tokens=True)
75
 
76
  inputs = tokenizer(
 
85
  outputs = model(**inputs)
86
 
87
  probs = torch.softmax(outputs.logits, dim=-1).flatten().tolist()
88
+
89
+ # 🎯 السطر الفائز المصلح: قراءة الخانة رقم 1 المخصصة لنسبة الخطر بدقة
90
+ unsafe_p = float(probs[1])
91
 
92
  if unsafe_p > 0.50:
93
  is_blocked = True