File size: 720 Bytes
33da398
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
from transformers import pipeline
import gradio as gr

# Load zero-shot classification pipeline
classifier = pipeline("zero-shot-classification", model="facebook/bart-large-mnli")

# Define possible topics
candidate_labels = ["politics", "sports", "technology", "education", "health", "entertainment", "climate change", "economy", "science", "travel"]

def classify_topic(text):
    result = classifier(text, candidate_labels)
    top_label = result['labels'][0]
    score = round(result['scores'][0], 2)
    return f"🏷️ Topic: {top_label} (Confidence: {score})"

# Gradio UI
iface = gr.Interface(fn=classify_topic, inputs="text", outputs="text", title="Intent / Topic Classifier")
iface.launch()