|
|
|
from transformers import AutoModelForSequenceClassification, AutoTokenizer, TextClassificationPipeline |
|
import gradio as gr |
|
|
|
new_model = AutoModelForSequenceClassification.from_pretrained('TeamQuad-fine-tuned-bert') |
|
new_tokenizer = AutoTokenizer.from_pretrained('TeamQuad-fine-tuned-bert') |
|
|
|
|
|
classifier = TextClassificationPipeline(model=new_model, tokenizer=new_tokenizer) |
|
|
|
|
|
label_mapping = {'LABEL_0': 'fake', 'LABEL_1': 'true'} |
|
|
|
|
|
def classify_news(text): |
|
result = classifier(text) |
|
|
|
label = result[0]['label'] |
|
score = result[0]['score'] |
|
mapped_result = {'label': label_mapping[label], 'score': score} |
|
return f"Label: {mapped_result['label']}, Score: {mapped_result['score']:.4f}" |
|
|
|
|
|
iface = gr.Interface( |
|
fn=classify_news, |
|
inputs=gr.Textbox(lines=10, placeholder="Enter a news headline or article to classify..."), |
|
outputs="text", |
|
title="Fake News Detection", |
|
description="Enter a news headline or article and see whether the model classifies it as 'Fake News' or 'True News'.", |
|
|
|
) |
|
|
|
|
|
iface.launch(share=True) |
|
|