Team Ai
Apppublic

trafaqat/Text_Classification

sourceHugging Faceapache-2.0updated 1y agoView on Hugging Face
0likes
app.py23 linesDownload Raw Back to root
1import gradio as gr2from transformers import pipeline3 4nlp = pipeline("text-classification")5 6def classify_text(input_text):7    result = nlp(input_text)[0]8    return result["label"], result["score"]9 10with gr.Blocks() as app:11    with gr.Row():12        with gr.Column():13            text_input = gr.Textbox(label="Enter text to classify")14            classify_btn = gr.Button(value="Classify")15        with gr.Column():16            label_output = gr.Textbox(label="Predicted label")17            score_output = gr.Textbox(label="Score")18 19    classify_btn.click(classify_text, inputs=text_input, outputs=[label_output, score_output], api_name="classify-text")20    examples = gr.Examples(examples=["This is a positive review.", "This is a negative review."],21                           inputs=[text_input])22 23app.launch()