|
import gradio as gr |
|
import joblib |
|
import pickle |
|
from huggingface_hub import hf_hub_download |
|
from tensorflow.keras.preprocessing.sequence import pad_sequences |
|
|
|
|
|
vectorizer_path = hf_hub_download(repo_id="sanaa-11/arabic-fake-news-classification", filename="tfidf_vectorizer (1).joblib") |
|
tokenizer_path = hf_hub_download(repo_id="sanaa-11/arabic-fake-news-classification", filename="tokenizer (1).pkl") |
|
model_path = hf_hub_download(repo_id="sanaa-11/arabic-fake-news-classification", filename="Logistic_Regression_model.joblib") |
|
|
|
vectorization = joblib.load(vectorizer_path) |
|
with open(tokenizer_path, "rb") as f: |
|
tokenizer = pickle.load(f) |
|
model = joblib.load(model_path) |
|
|
|
|
|
def predict_news(news_text): |
|
|
|
tfidf_vector = vectorization.transform([news_text]) |
|
|
|
|
|
prediction = model.predict(tfidf_vector) |
|
return "Fake News" if prediction[0] == 0 else "Real News" |
|
|
|
|
|
|
|
interface = gr.Interface( |
|
fn=predict_news, |
|
inputs=gr.Textbox(label="Enter Arabic News Text"), |
|
outputs=gr.Label(label="Prediction"), |
|
title="Arabic Fake News Classifier", |
|
description="Classifies Arabic news articles as Fake or Real." |
|
) |
|
|
|
|
|
interface.launch() |