cornelliusyudhawijaya
commited on
Commit
•
8bbec37
1
Parent(s):
e5bb6cd
Create app.py
Browse files
app.py
ADDED
@@ -0,0 +1,20 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import gradio as gr
|
2 |
+
from transformers import pipeline
|
3 |
+
|
4 |
+
model_name = "cornelliusyudhawijaya/AG_News_Classification_DistillBert"
|
5 |
+
classifier = pipeline("text-classification", model=model_name, tokenizer=model_name)
|
6 |
+
|
7 |
+
def classify_text(text):
|
8 |
+
result = classifier(text)[0]
|
9 |
+
return f"Label: {result['label']}, Score: {result['score']:.4f}"
|
10 |
+
|
11 |
+
iface = gr.Interface(
|
12 |
+
fn=classify_text,
|
13 |
+
inputs=gr.inputs.Textbox(lines=2, placeholder="Enter text here..."),
|
14 |
+
outputs="text",
|
15 |
+
title="Text Classification",
|
16 |
+
description="Enter text to classify the news."
|
17 |
+
)
|
18 |
+
|
19 |
+
if __name__ == "__main__":
|
20 |
+
iface.launch()
|