Spaces:
Sleeping
Sleeping
Download app.py from piyush2205/topic_classification: direct link, hf CLI and curl.
- Browser
- Download file 720 Bytes
-
https://huggingface.co/spaces/piyush2205/topic_classification/resolve/main/app.py
- Command line
-
hf download hf://spaces/piyush2205/topic_classification/app.py
-
curl -L -o app.py https://huggingface.co/spaces/piyush2205/topic_classification/resolve/main/app.py
720 Bytes
| 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() | |