|
import gradio as gr |
|
import numpy as np |
|
import pandas as pd |
|
from transformers import AutoModelForSequenceClassification, AutoTokenizer, pipeline |
|
|
|
|
|
model_path = "bert_model" |
|
model = AutoModelForSequenceClassification.from_pretrained(model_path) |
|
tokenizer = AutoTokenizer.from_pretrained(model_path) |
|
|
|
|
|
clf = pipeline("text-classification", model=model, tokenizer=tokenizer) |
|
|
|
|
|
def classify_fake_news(text): |
|
prediction = clf.predict(text)[0]["score"] |
|
|
|
label = "Fake" if prediction < 0.7 else "Real" |
|
return label |
|
|
|
|
|
iface = gr.Interface( |
|
fn=classify_fake_news, |
|
inputs="text", |
|
outputs="label", |
|
title="BERT & CatBoost Fake News Detection", |
|
description="Paste a news or tweet to check if it's fake or real." |
|
) |
|
|
|
|
|
iface.launch(share=True) |
|
|