sanaa-11's picture
Update app.py
68670c2 verified
import gradio as gr
import joblib
import pickle
from huggingface_hub import hf_hub_download
from tensorflow.keras.preprocessing.sequence import pad_sequences
# Load the Tokenizer, TfidfVectorizer, and Logistic Regression model
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)
# Define the prediction function
def predict_news(news_text):
# Preprocess the input text directly using TfidfVectorizer
tfidf_vector = vectorization.transform([news_text])
# Predict with the model
prediction = model.predict(tfidf_vector)
return "Fake News" if prediction[0] == 0 else "Real News"
# Create Gradio interface
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."
)
# Launch the app
interface.launch()