| | import gradio as gr |
| | from transformers import pipeline |
| |
|
| | |
| | classifier = pipeline("zero-shot-classification") |
| |
|
| |
|
| | def classify_text(text, additional_labels): |
| | |
| | labels = ["Education", "Business", "Sports", "Manufacturing"] |
| |
|
| | |
| | if additional_labels: |
| | custom_labels = additional_labels.split(',') |
| | labels.extend(custom_labels) |
| |
|
| | |
| | result = classifier(text, candidate_labels=labels) |
| |
|
| | |
| | output = [] |
| | for label, score in zip(result["labels"], result["scores"]): |
| | output.append(f"Label: {label}, Score: {round(score, 4)}") |
| | return "\n".join(output) |
| |
|
| |
|
| | |
| | interface = gr.Interface( |
| | fn=classify_text, |
| | inputs=["text", "text"], |
| | outputs="text", |
| | title="Text Classification", |
| | description="Enter a text to classify into categories: Education, Business, Sports, Manufacturing. Optionally, add more categories separated by commas." |
| | ) |
| |
|
| | |
| | interface.launch() |