Spaces:
Running
Running
import gradio as gr | |
import re | |
import string | |
import pickle | |
# Load trained model and vectorizer | |
with open("svm_model.pkl", "rb") as model_file: | |
svm_model = pickle.load(model_file) | |
with open("vectorizer.pkl", "rb") as vectorizer_file: | |
vectorizer = pickle.load(vectorizer_file) | |
# Preprocessing function | |
def preprocess_text(text): | |
text = text.lower() | |
text = re.sub(f"[{string.punctuation}]", "", text) # Remove punctuation | |
text = re.sub(r"\d+", "", text) # Remove numbers | |
return text | |
# Function to predict news authenticity | |
def predict_news(news_text): | |
processed_text = preprocess_text(news_text) | |
text_tfidf = vectorizer.transform([processed_text]) | |
prediction = svm_model.predict(text_tfidf) | |
return "Real" if prediction[0] == 1 else "Fake" | |
# Gradio UI | |
iface = gr.Interface( | |
fn=predict_news, | |
inputs=gr.Textbox(lines=5, placeholder="Enter news here..."), | |
outputs="text", | |
title="Fake News Detection", | |
description="Enter a news article and check if it's real or fake." | |
) | |
iface.launch() | |