|
import gradio as gr |
|
from transformers import pipeline |
|
|
|
|
|
classifier = pipeline("zero-shot-classification", model="facebook/bart-large-mnli") |
|
|
|
|
|
def classify_text(text): |
|
candidate_labels = ["Technology", "Health", "Sports", "Politics", "Education", "Art", "Economy"] |
|
result = classifier(text, candidate_labels=candidate_labels) |
|
highest_confidence_label = result['labels'][0] |
|
confidence = result['scores'][0] |
|
|
|
return f"Topic: {highest_confidence_label}, Confidence: {confidence:.2f}" |
|
|
|
|
|
iface = gr.Interface( |
|
fn=classify_text, |
|
inputs="text", |
|
outputs="text", |
|
title="Text Classification by Topic", |
|
description="Enter a text, and we'll classify it by topic (Technology, Health, Sports, Politics, etc.)." |
|
) |
|
|
|
|
|
if __name__ == "__main__": |
|
iface.launch() |
|
|