File size: 1,186 Bytes
c43c17d
 
 
 
8438621
c43c17d
 
 
 
 
 
 
 
5f8c0cf
 
 
 
 
 
 
 
 
 
c43c17d
 
 
 
 
 
5f8c0cf
c43c17d
 
 
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
import os
os.system('pip install transformers gradio torch')
from transformers import AutoTokenizer, AutoModelForSequenceClassification
import gradio as gr
import torch.nn.functional as F

tokenizer = AutoTokenizer.from_pretrained("EXt1/mdeberta-v3-base-thai-fakenews")  
model = AutoModelForSequenceClassification.from_pretrained("EXt1/mdeberta-v3-base-thai-fakenews")  

def classify_fake_news(text):
    inputs = tokenizer(text, return_tensors="pt", truncation=True, padding=True)
    outputs = model(**inputs)
    logits = outputs.logits
    probs = F.softmax(logits, dim=1) 
    probs = probs.detach().cpu().numpy()[0]

    labels = ["Real News", "Fake News"]  
    predicted_class = probs.argmax()

    label = labels[predicted_class]
    prob = float(probs[predicted_class]) * 100  

    return label, f"{prob:.2f}%"

# Create Gradio interface
gr.Interface(
    fn=classify_fake_news,
    inputs=gr.Textbox(lines=8, placeholder="Enter text here..."), 
    outputs="text",
    title="Thai Fake News Classification using mdeberta-v3-base",
    description="Classifies Thai News as Fake or Real with 91 percent accuracy using a fine-tuned BERT model",
    theme="compact"
).launch()