File size: 1,214 Bytes
f17df59
fa6e8e3
413299e
ff2b079
5cc26f5
f17df59
 
8242585
f17df59
54dc2ca
fa6e8e3
 
54dc2ca
f17df59
 
 
 
 
 
 
54dc2ca
f17df59
 
fa6e8e3
f17df59
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
33
34
35
36
37
38
39
40
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()