File size: 1,604 Bytes
36c77ab
 
 
 
5c74af6
 
 
 
 
36c77ab
 
5c74af6
 
36c77ab
5c74af6
36c77ab
 
5c74af6
36c77ab
5c74af6
 
 
36c77ab
 
5c74af6
36c77ab
5c74af6
 
36c77ab
 
 
 
 
 
 
 
 
 
 
5c74af6
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
41
import gradio as gr
import torch
from transformers import BertTokenizerFast, BertForSequenceClassification

def predict_news_category(text, model, tokenizer):
    # Tokenize input text
    inputs = tokenizer(text, truncation=True, padding=True, max_length=512, return_tensors='pt')
    
    # Predict
    outputs = model(**inputs)
    probs = outputs[0].softmax(1)
    
    # Get the predicted category
    _, predicted_category = torch.max(probs, dim=1)
    
    return predicted_category.item()

# Load your model
model = BertForSequenceClassification.from_pretrained('akhil2808/EPICS-PROJECT')
model.eval()  # Set the model to evaluation mode

# Load tokenizer
tokenizer = BertTokenizerFast.from_pretrained('akhil2808/EPICS-PROJECT')

# Function to predict news category
def detect_news_category(text):
    category = predict_news_category(text, model, tokenizer)
    # Map the prediction to fake or real news
    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()