File size: 954 Bytes
e3db267
 
 
b9c7b1c
e3db267
b9c7b1c
 
 
 
e3db267
b9c7b1c
 
e3db267
 
 
15ba155
e3db267
b9c7b1c
e3db267
 
 
 
 
6a7b5a6
e3db267
 
25ef61b
e3db267
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
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)