Upload 5 files
Browse files- .gitattributes +1 -0
- Model Accuracy.png +0 -0
- README.md +49 -0
- app.py +68 -0
- fake_news_pipeline.skops +3 -0
- requirements.txt +5 -0
.gitattributes
CHANGED
|
@@ -33,3 +33,4 @@ saved_model/**/* filter=lfs diff=lfs merge=lfs -text
|
|
| 33 |
*.zip filter=lfs diff=lfs merge=lfs -text
|
| 34 |
*.zst filter=lfs diff=lfs merge=lfs -text
|
| 35 |
*tfevents* filter=lfs diff=lfs merge=lfs -text
|
|
|
|
|
|
| 33 |
*.zip filter=lfs diff=lfs merge=lfs -text
|
| 34 |
*.zst filter=lfs diff=lfs merge=lfs -text
|
| 35 |
*tfevents* filter=lfs diff=lfs merge=lfs -text
|
| 36 |
+
fake_news_pipeline.skops filter=lfs diff=lfs merge=lfs -text
|
Model Accuracy.png
ADDED
|
README.md
CHANGED
|
@@ -1,3 +1,52 @@
|
|
| 1 |
---
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 2 |
license: mit
|
|
|
|
|
|
|
|
|
|
| 3 |
---
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
---
|
| 2 |
+
title: Fake News Detector (Pipeline)
|
| 3 |
+
library_name: sklearn
|
| 4 |
+
tags:
|
| 5 |
+
- text-classification
|
| 6 |
+
- fake-news
|
| 7 |
+
- sklearn
|
| 8 |
+
- logistic-regression
|
| 9 |
+
- pipeline
|
| 10 |
license: mit
|
| 11 |
+
sdk: gradio
|
| 12 |
+
sdk_version: 4.31.0
|
| 13 |
+
app_file: app.py
|
| 14 |
---
|
| 15 |
+
|
| 16 |
+
## 📰 Fake News Detector (Professional Pipeline)
|
| 17 |
+
|
| 18 |
+
هذا نموذج **Scikit-learn Pipeline** تم تدريبه لتصنيف المقالات الإخبارية إلى "حقيقية (True)" أو "كاذبة (Fake)".
|
| 19 |
+
|
| 20 |
+
### 🚀 كيف يعمل؟
|
| 21 |
+
|
| 22 |
+
يستخدم النموذج `Pipeline` احترافي يدمج خطوتين في خطوة واحدة:
|
| 23 |
+
1. **TF-IDF Vectorizer**: لتحويل النص إلى مصفوفة رقمية.
|
| 24 |
+
2. **Logistic Regression**: لعملية التصنيف.
|
| 25 |
+
|
| 26 |
+
### 📈 أداء النموذج
|
| 27 |
+
|
| 28 |
+
حقق النموذج دقة **96.50%** على مجموعة الاختبار.
|
| 29 |
+
``
|
| 30 |
+
|
| 31 |
+
### 🛠️ كيفية الاستخدام (في Python)
|
| 32 |
+
|
| 33 |
+
بفضل الـ Pipeline، أصبح الاستخدام بسيطاً جداً:
|
| 34 |
+
|
| 35 |
+
```python
|
| 36 |
+
import skops.io as sio
|
| 37 |
+
|
| 38 |
+
# تحميل ملف الـ Pipeline الواحد
|
| 39 |
+
pipeline = sio.load("fake_news_pipeline.skops", trusted=True)
|
| 40 |
+
|
| 41 |
+
# نص للتجربة
|
| 42 |
+
text_to_test = "Your sample news text goes here..."
|
| 43 |
+
|
| 44 |
+
# التنبؤ مباشرة (الـ Pipeline يتولى التحويل والتنبؤ)
|
| 45 |
+
prediction_label = pipeline.predict([text_to_test])[0]
|
| 46 |
+
probabilities = pipeline.predict_proba([text_to_test])[0]
|
| 47 |
+
|
| 48 |
+
label = "True" if prediction_label == 1 else "Fake"
|
| 49 |
+
confidence = probabilities[prediction_label]
|
| 50 |
+
|
| 51 |
+
print(f"Prediction: {label}")
|
| 52 |
+
print(f"Confidence: {confidence:.2f}")
|
app.py
ADDED
|
@@ -0,0 +1,68 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import gradio as gr
|
| 2 |
+
import skops.io as sio
|
| 3 |
+
from pathlib import Path
|
| 4 |
+
import logging
|
| 5 |
+
|
| 6 |
+
# --- 1. إعدادات التسجيل (Logging) ---
|
| 7 |
+
logging.basicConfig(level=logging.INFO)
|
| 8 |
+
|
| 9 |
+
# --- 2. تحميل الـ Pipeline ---
|
| 10 |
+
PIPELINE_PATH = Path("fake_news_pipeline.skops")
|
| 11 |
+
pipeline = None
|
| 12 |
+
|
| 13 |
+
try:
|
| 14 |
+
logging.info(f"Loading pipeline from {PIPELINE_PATH}...")
|
| 15 |
+
pipeline = sio.load(PIPELINE_PATH, trusted=True)
|
| 16 |
+
logging.info("Pipeline loaded successfully.")
|
| 17 |
+
except Exception as e:
|
| 18 |
+
logging.error(f"Error loading pipeline: {e}")
|
| 19 |
+
# هذا سيظهر الخطأ على واجهة Gradio إذا فشل التحميل
|
| 20 |
+
raise gr.Error(f"Failed to load model: {e}")
|
| 21 |
+
|
| 22 |
+
# --- 3. دالة التنبؤ (أصبحت أبسط) ---
|
| 23 |
+
def predict_news(text: str):
|
| 24 |
+
"""
|
| 25 |
+
دالة للتنبؤ بما إذا كان النص "Fake" أو "True" باستخدام الـ Pipeline.
|
| 26 |
+
"""
|
| 27 |
+
if not text:
|
| 28 |
+
return {"Fake": 0, "True": 0}
|
| 29 |
+
|
| 30 |
+
if pipeline is None:
|
| 31 |
+
return {"Error": "Model is not loaded."}
|
| 32 |
+
|
| 33 |
+
try:
|
| 34 |
+
# الـ Pipeline يتولى (transform) و (predict) في خطوة واحدة
|
| 35 |
+
# predict_proba يُرجع [[prob_0, prob_1]]
|
| 36 |
+
probabilities = pipeline.predict_proba([text])[0]
|
| 37 |
+
|
| 38 |
+
# 0 = Fake, 1 = True (بناءً على ملف التدريب)
|
| 39 |
+
output_labels = {
|
| 40 |
+
"Fake": float(probabilities[0]),
|
| 41 |
+
"True": float(probabilities[1])
|
| 42 |
+
}
|
| 43 |
+
return output_labels
|
| 44 |
+
|
| 45 |
+
except Exception as e:
|
| 46 |
+
logging.error(f"Error during prediction: {e}")
|
| 47 |
+
return {"Error": str(e)}
|
| 48 |
+
|
| 49 |
+
# --- 4. واجهة Gradio (كما هي) ---
|
| 50 |
+
example_fake = "Donald Trump Sends Out Embarrassing New Year’s Eve Message; This is Disturbing"
|
| 51 |
+
example_true = "WASHINGTON (Reuters) - The head of a conservative Republican faction in the U.S. Congress, who voted this month for a huge expansion of the national debt to pay for tax cuts, called himself a “fiscal conservative” on Sunday..."
|
| 52 |
+
|
| 53 |
+
iface = gr.Interface(
|
| 54 |
+
fn=predict_news,
|
| 55 |
+
inputs=gr.Textbox(lines=10, label="أدخل نص الخبر هنا", placeholder="...اكتب نص المقال..."),
|
| 56 |
+
outputs=gr.Label(num_top_classes=2, label="النتيجة"),
|
| 57 |
+
title="🤖 Fake News Detector ",
|
| 58 |
+
description="هذا النموذج هو كاشف للأخبار الكاذبة (باستخدام Pipeline) تم تدريبه باستخدام Logistic Regression و TF-IDF. أدخل نص مقال إخباري لمعرفة تصنيفه (True أو Fake).",
|
| 59 |
+
examples=[
|
| 60 |
+
[example_fake],
|
| 61 |
+
[example_true]
|
| 62 |
+
],
|
| 63 |
+
allow_flagging="never"
|
| 64 |
+
)
|
| 65 |
+
|
| 66 |
+
# --- 5. تشغيل التطبيق ---
|
| 67 |
+
if __name__ == "__main__":
|
| 68 |
+
iface.launch()
|
fake_news_pipeline.skops
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:340163893b80499e0a9288e386446b075c79a60685b32b1c4333234c2309be10
|
| 3 |
+
size 71291401
|
requirements.txt
ADDED
|
@@ -0,0 +1,5 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
scikit-learn
|
| 2 |
+
gradio
|
| 3 |
+
gunicorn
|
| 4 |
+
skops
|
| 5 |
+
pandas
|