|
from transformers import pipeline |
|
import gradio as gr |
|
|
|
repo_id = "pamunarr/P7EjOpc1-MecAt" |
|
|
|
classifier = pipeline('text-classification', model=repo_id) |
|
labels = { |
|
"LABEL_0" : "World" , "LABEL_1" : "Nigeria" , "LABEL_2" : "Health" , |
|
"LABEL_3" : "Africa" , "LABEL_4" : "Politics" |
|
} |
|
|
|
def predict(text): |
|
scores = classifier(text , top_k = 5) |
|
return {labels[dicc["label"]] : dicc["score"] for dicc in scores} |
|
|
|
gr.Interface(fn=predict, inputs="text", outputs=gr.components.Label(num_top_classes=5)).launch(share=False) |