import gradio as gr import numpy as np import pandas as pd from transformers import AutoModelForSequenceClassification, AutoTokenizer, pipeline # Load the model and tokenizer from the folder model_path = "bert_model" model = AutoModelForSequenceClassification.from_pretrained(model_path) tokenizer = AutoTokenizer.from_pretrained(model_path) # Create the pipeline clf = pipeline("text-classification", model=model, tokenizer=tokenizer) # Define function for fake news detection def classify_fake_news(text): prediction = clf.predict(text)[0]["score"] # Convert prediction to label label = "Fake" if prediction < 0.7 else "Real" return label # Define Gradio interface 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." ) # Launch the Gradio interface iface.launch(share=True)