Dhom1 commited on
Commit
bfb7595
·
verified ·
1 Parent(s): 3a838cd

Update src/streamlit_app.py

Browse files
Files changed (1) hide show
  1. src/streamlit_app.py +19 -9
src/streamlit_app.py CHANGED
@@ -75,15 +75,26 @@ with col2:
75
  # ✅ إدخال الإعلان
76
  uploaded_text = st.text_area("✍️ أدخل نص الإعلان هنا:", height=150)
77
 
78
- # ✅ تصنيف الإعلان + فحص العبارات في نفس الوقت
79
- # ✅ تصنيف الإعلان + فحص العبارات في نفس الوقت (بدون عرض تفاصيل النموذج)
80
  if uploaded_text:
81
  try:
82
  # تصنيف النموذج ML
83
  pred = classifier.predict([uploaded_text])[0]
84
-
85
- # فحص العبارات المخالفة
86
- violations = [kw for kw in offensive_keywords if kw in uploaded_text]
 
 
 
 
 
 
 
 
 
 
 
 
87
  has_violations = len(violations) > 0
88
 
89
  # منطق التصنيف النهائي
@@ -94,17 +105,16 @@ if uploaded_text:
94
  else:
95
  final_label = "❌ إعلان مخالف"
96
 
97
- # عرض التصنيف النهائي فقط
98
  st.markdown(f'<div class="metric-container"><h4>{final_label}</h4></div>', unsafe_allow_html=True)
99
 
100
  except Exception as e:
101
  st.error(f"حدث خطأ في التنبؤ: {str(e)}")
102
 
103
-
104
- # ✅ تحليل العبارات (تفصيل العبارات المخالفة + نسبة)
105
  if st.button("🔍 تحليل العبارات"):
106
  if uploaded_text:
107
- violations = [kw for kw in offensive_keywords if kw in uploaded_text]
108
  if violations:
109
  st.error("❌ الإعلان يحتوي على عبارات مخالفة:")
110
  for v in violations:
 
75
  # ✅ إدخال الإعلان
76
  uploaded_text = st.text_area("✍️ أدخل نص الإعلان هنا:", height=150)
77
 
78
+ # ✅ تصنيف الإعلان + فحص العبارات الكاملة والجزئية
 
79
  if uploaded_text:
80
  try:
81
  # تصنيف النموذج ML
82
  pred = classifier.predict([uploaded_text])[0]
83
+
84
+ # كلمات مفتاحية جزئية (مرنة)
85
+ flag_keywords = [
86
+ "للنساء", "للرجال", "النساء فقط", "الرجال فقط", "فقط", "جنسية", "شرط العمر",
87
+ "بدون عقد", "بدون تأمين", "مظهر لائق", "تحمل ضغط", "الوظيفة للذكور", "مطلوب نساء",
88
+ "يفضل سعودية", "دوام جزئي", "دوام مسائي", "راتب", "مغري", "جاذب", "الزي الرسمي"
89
+ ]
90
+
91
+ # تطابق حرفي كامل
92
+ phrase_matches = [kw for kw in offensive_keywords if kw in uploaded_text]
93
+ # تطابق جزئي بالكلمات
94
+ keyword_matches = [k for k in flag_keywords if k in uploaded_text]
95
+
96
+ # الدمج النهائي
97
+ violations = list(set(phrase_matches + keyword_matches))
98
  has_violations = len(violations) > 0
99
 
100
  # منطق التصنيف النهائي
 
105
  else:
106
  final_label = "❌ إعلان مخالف"
107
 
108
+ # عرض النتيجة النهائية فقط
109
  st.markdown(f'<div class="metric-container"><h4>{final_label}</h4></div>', unsafe_allow_html=True)
110
 
111
  except Exception as e:
112
  st.error(f"حدث خطأ في التنبؤ: {str(e)}")
113
 
114
+ # ✅ تحليل العبارات (تفصيل المخالفات + نسبة)
 
115
  if st.button("🔍 تحليل العبارات"):
116
  if uploaded_text:
117
+ violations = list(set(phrase_matches + keyword_matches))
118
  if violations:
119
  st.error("❌ الإعلان يحتوي على عبارات مخالفة:")
120
  for v in violations: