add model requirements
Browse files- app.py +29 -0
- requirements.txt +3 -0
app.py
ADDED
@@ -0,0 +1,29 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import os
|
2 |
+
os.system('pip install transformers gradio torch')
|
3 |
+
from transformers import AutoTokenizer, AutoModelForSequenceClassification
|
4 |
+
import gradio as gr
|
5 |
+
|
6 |
+
|
7 |
+
tokenizer = AutoTokenizer.from_pretrained("EXt1/mdeberta-v3-base-thai-fakenews")
|
8 |
+
model = AutoModelForSequenceClassification.from_pretrained("EXt1/mdeberta-v3-base-thai-fakenews")
|
9 |
+
|
10 |
+
def classify_fake_news(text):
|
11 |
+
inputs = tokenizer(text, return_tensors="pt", truncation=True, padding=True)
|
12 |
+
outputs = model(**inputs)
|
13 |
+
logits = outputs.logits
|
14 |
+
predicted_class = logits.argmax().item()
|
15 |
+
|
16 |
+
if predicted_class == 1:
|
17 |
+
return "Fake News"
|
18 |
+
else:
|
19 |
+
return "Real News"
|
20 |
+
|
21 |
+
# Create Gradio interface
|
22 |
+
gr.Interface(
|
23 |
+
fn=classify_fake_news,
|
24 |
+
inputs=gr.Textbox(lines=8, placeholder="Enter text here..."),
|
25 |
+
outputs="text",
|
26 |
+
title="Thai Fake News Classification using BERT",
|
27 |
+
description="Classifies Thai News as Fake or Real with 91 percent accuracy using a fine-tuned BERT model",
|
28 |
+
theme="compact"
|
29 |
+
).launch()
|
requirements.txt
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
transformers
|
2 |
+
gradio
|
3 |
+
torch
|