roncc13 commited on
Commit
4de736a
·
verified ·
1 Parent(s): b8cd12b

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +35 -0
app.py ADDED
@@ -0,0 +1,35 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ from transformers import AutoTokenizer, AutoModelForSequenceClassification
3
+ import torch
4
+
5
+ MODEL_ID = "roncc13/trainCMDBERT-sample"
6
+
7
+ tokenizer = AutoTokenizer.from_pretrained(MODEL_ID)
8
+ model = AutoModelForSequenceClassification.from_pretrained(MODEL_ID)
9
+
10
+ # Adjust these to match your label order
11
+ label_names = ["fake", "real"]
12
+
13
+ def classify(text):
14
+ inputs = tokenizer(
15
+ text,
16
+ return_tensors="pt",
17
+ truncation=True,
18
+ padding=True,
19
+ max_length=256
20
+ )
21
+ with torch.no_grad():
22
+ outputs = model(**inputs)
23
+ probs = torch.softmax(outputs.logits, dim=-1)[0].tolist()
24
+ return {label_names[i]: float(probs[i]) for i in range(len(label_names))}
25
+
26
+ demo = gr.Interface(
27
+ fn=classify,
28
+ inputs=gr.Textbox(lines=4, label="Enter Cebuano news text"),
29
+ outputs=gr.Label(num_top_classes=2, label="Prediction"),
30
+ title="CMD-BERT Cebuano Fake News Detector",
31
+ description="Paste Cebuano news text to check if it is likely fake or real."
32
+ )
33
+
34
+ if __name__ == "__main__":
35
+ demo.launch()