Update app.py
Browse files
app.py
CHANGED
@@ -4,19 +4,19 @@ from transformers import pipeline
|
|
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 |
-
|
|
|
|
|
10 |
|
11 |
# Define the Gradio interface using the new API
|
12 |
iface = gr.Interface(
|
13 |
fn=classify_text,
|
14 |
inputs=gr.Textbox(lines=2, placeholder="Enter text here..."),
|
15 |
outputs="text",
|
16 |
-
title="
|
17 |
description="Enter text to classify the news."
|
18 |
-
)
|
19 |
-
|
20 |
-
# Launch the interface
|
21 |
-
if __name__ == "__main__":
|
22 |
-
iface.launch()
|
|
|
4 |
model_name = "cornelliusyudhawijaya/AG_News_Classification_DistillBert"
|
5 |
classifier = pipeline("text-classification", model=model_name, tokenizer=model_name)
|
6 |
|
7 |
+
label_names = {0: 'World', 1: 'Sports', 2: 'Business', 3: 'Sci/Tech'}
|
8 |
+
|
9 |
def classify_text(text):
|
10 |
result = classifier(text)[0]
|
11 |
+
label_id = int(result['label'].split('_')[-1])
|
12 |
+
label_name = label_names[label_id]
|
13 |
+
return f"Label: {label_name}, Score: {result['score']:.4f}"
|
14 |
|
15 |
# Define the Gradio interface using the new API
|
16 |
iface = gr.Interface(
|
17 |
fn=classify_text,
|
18 |
inputs=gr.Textbox(lines=2, placeholder="Enter text here..."),
|
19 |
outputs="text",
|
20 |
+
title="News Classification",
|
21 |
description="Enter text to classify the news."
|
22 |
+
)
|
|
|
|
|
|
|
|