ML-Project / app.py
KenLumod's picture
Update app.py
ff2b079 verified
import gradio as gr
from transformers import pipeline, AutoConfig, AutoModelForSequenceClassification
model_id = "KenLumod/ML-Project-Fake-Real-News-Detector-Final"
# Force reload model with updated config
config = AutoConfig.from_pretrained(model_id)
config.id2label = {1: "Fake News", 0: "Real News"} # Force override
config.label2id = {v: k for k, v in config.id2label.items()}
# Load the model using AutoModelForSequenceClassification
model = AutoModelForSequenceClassification.from_pretrained(model_id, config=config)
# Create the pipeline for classification
classifier = pipeline(
"text-classification",
model=model,
tokenizer=model_id,
return_all_scores=False
)
def classify_news(text):
result = classifier(text)[0]
print(result) # Inspect the output
return result['label']
demo = gr.Interface(
fn=classify_news,
inputs=gr.Textbox(lines=6, placeholder="Enter news article here..."),
outputs="text",
title="Fake News Detector",
description="Classifies news articles as Fake or Real",
examples=[
["Breaking: Scientists discover chocolate prevents aging!"],
["Parliament passes new climate change legislation"]
]
)
demo.launch()