Spaces:
Sleeping
Sleeping
Create app.py
Browse files
app.py
ADDED
|
@@ -0,0 +1,47 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import gradio as gr
|
| 2 |
+
import joblib
|
| 3 |
+
from huggingface_hub import hf_hub_download
|
| 4 |
+
|
| 5 |
+
# --- 1. تحميل النموذج الخاص بك من مستودعك ---
|
| 6 |
+
REPO_ID = "Ma120/clickbait-detector"
|
| 7 |
+
FILENAME = "clickbait_model.pkl"
|
| 8 |
+
|
| 9 |
+
print(f"Loading model {FILENAME} from {REPO_ID}...")
|
| 10 |
+
model_path = hf_hub_download(repo_id=REPO_ID, filename=FILENAME)
|
| 11 |
+
model = joblib.load(model_path)
|
| 12 |
+
print("Model loaded successfully.")
|
| 13 |
+
|
| 14 |
+
# --- 2. تعريف الدالة التي ستنفذ التصنيف ---
|
| 15 |
+
def classify_headline(headline):
|
| 16 |
+
prediction = model.predict([headline])[0]
|
| 17 |
+
probabilities = model.predict_proba([headline])[0]
|
| 18 |
+
|
| 19 |
+
if prediction == 1:
|
| 20 |
+
confidences = {
|
| 21 |
+
"Clickbait": float(probabilities[1]),
|
| 22 |
+
"Not Clickbait": float(probabilities[0])
|
| 23 |
+
}
|
| 24 |
+
else:
|
| 25 |
+
confidences = {
|
| 26 |
+
"Not Clickbait": float(probabilities[0]),
|
| 27 |
+
"Clickbait": float(probabilities[1])
|
| 28 |
+
}
|
| 29 |
+
return confidences
|
| 30 |
+
|
| 31 |
+
# --- 3. بناء الواجهة الرسومية ---
|
| 32 |
+
inputs = gr.Textbox(
|
| 33 |
+
label="Enter a Headline:",
|
| 34 |
+
placeholder="e.g., You Won't Believe What Happens Next!"
|
| 35 |
+
)
|
| 36 |
+
outputs = gr.Label(label="Result", num_top_classes=2)
|
| 37 |
+
|
| 38 |
+
demo = gr.Interface(
|
| 39 |
+
fn=classify_headline,
|
| 40 |
+
inputs=inputs,
|
| 41 |
+
outputs=outputs,
|
| 42 |
+
title="Clickbait Detector",
|
| 43 |
+
description="Enter a news headline to see if it's clickbait or not. Model trained by Ma120."
|
| 44 |
+
)
|
| 45 |
+
|
| 46 |
+
# --- 4. تشغيل الواجهة ---
|
| 47 |
+
demo.launch()
|