|
import gradio as gr |
|
from transformers import pipeline |
|
|
|
|
|
classifier = pipeline("text-classification", model="distilbert-base-uncased") |
|
|
|
|
|
def classify_text(text): |
|
result = classifier(text) |
|
return {label: round(score, 2) for label, score in zip(result[0]['labels'], result[0]['scores'])} |
|
|
|
|
|
iface = gr.Interface( |
|
fn=classify_text, |
|
inputs=gr.Textbox(lines=5, placeholder="Enter text here..."), |
|
outputs="json", |
|
title="Text Classification App", |
|
description="This app classifies your text into predefined categories and shows the confidence scores." |
|
) |
|
|
|
iface.launch() |