File size: 809 Bytes
8bbec37
 
 
 
 
 
b03c62c
 
8bbec37
 
b03c62c
 
 
8bbec37
8404c84
8bbec37
 
8404c84
8bbec37
b03c62c
8bbec37
d120102
 
 
 
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
import gradio as gr
from transformers import pipeline

model_name = "cornelliusyudhawijaya/AG_News_Classification_DistillBert"
classifier = pipeline("text-classification", model=model_name, tokenizer=model_name)

label_names = {0: 'World', 1: 'Sports', 2: 'Business', 3: 'Sci/Tech'}

def classify_text(text):
    result = classifier(text)[0]
    label_id = int(result['label'].split('_')[-1]) 
    label_name = label_names[label_id] 
    return f"Label: {label_name}, Score: {result['score']:.4f}"

# Define the Gradio interface using the new API
iface = gr.Interface(
    fn=classify_text,
    inputs=gr.Textbox(lines=2, placeholder="Enter text here..."),
    outputs="text",
    title="News Classification",
    description="Enter text to classify the news."
)

if __name__ == "__main__":
    iface.launch()