Spaces:
Sleeping
Sleeping
File size: 1,084 Bytes
27ff273 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 |
import gradio as gr
from transformers import pipeline
def classifier(sentence):
classifier = pipeline(
"text-classification",
model="AirrStorm/DistilBERT-SST2",
tokenizer="AirrStorm/DistilBERT-SST2",
device=0
)
label_mapping = {"LABEL_0": "negative", "LABEL_1": "positive"}
result = classifier(sentence)
predicted_label = label_mapping[result[0]['label']]
return predicted_label # Should print "negative" or "positive"
# Define the Gradio Interface
demo = gr.Interface(
fn=classifier,
inputs=gr.Textbox(
lines=4,
placeholder="Type a sentence to classify the sentiment...",
label="Input Text"
),
outputs=gr.Textbox(
label="Predicted Sentiment"
),
title="Sentiment Analysis",
description="Classify the sentiment of the input text as positive or negative.",
theme="hugging-face", # Optional, you can experiment with other themes like 'huggingface'
allow_flagging="never", # Disable flagging if not needed
)
# Launch the interface
demo.launch()
|