akhil2808's picture
Rename updateapp.py to app.py
efc6fe9
raw
history blame
1.48 kB
import gradio as gr
import torch
from transformers import BertTokenizerFast, BertForSequenceClassification
def predict_news_category(text, model, tokenizer, device):
inputs = tokenizer(text, truncation=True, padding=True, max_length=512, return_tensors='pt').to(device)
model.to(device)
outputs = model(**inputs)
probs = outputs[0].softmax(1)
_, predicted_category = torch.max(probs, dim=1)
return predicted_category.item()
model = BertForSequenceClassification.from_pretrained('akhil2808/EPICS-PROJECT')
model.eval()
tokenizer = BertTokenizerFast.from_pretrained('akhil2808/EPICS-PROJECT')
def detect_news_category(text):
device = torch.device('cuda' if torch.cuda.is_available() else 'cpu')
category = predict_news_category(text, model, tokenizer, device)
prediction_dict = {1: 'Real News', 0: 'Fake News'}
return prediction_dict[category]
iface = gr.Interface(fn=detect_news_category,
inputs=gr.inputs.Textbox(lines=7, placeholder='News Here...'),
outputs='text',
title='Disinformation Detector',
description='In the age of information, disinformation spreads rapidly. Fake news can cause substantial harm and mislead people. Therefore, it\'s crucial to detect and debunk fake news. This tool helps to detect disinformation by classifying the news as "Real" or "Fake". Powered by Group 40.',
theme='huggingface')
iface.launch()