Saurav21's picture
upload to huggingface spaces
fb3ac56
from transformers import AutoTokenizer, AutoModelForSequenceClassification, pipeline
import gradio as gr
def text_sentiments(text):
model_name = "distilbert-base-uncased-finetuned-sst-2-english"
model = AutoModelForSequenceClassification.from_pretrained(model_name)
tokenizer = AutoTokenizer.from_pretrained(model_name)
classifier = pipeline(task= "sentiment-analysis", model = model, tokenizer = tokenizer)
result = classifier(text)
label = result[0]["label"]
score = result[0]["score"] * 100
return f"Sentiment is : {label} and Confidence is : {score: 0.2f} %"
gr.Interface(fn = text_sentiments,
inputs = gr.inputs.Textbox(label = "Input Text"),
outputs = gr.outputs.Textbox(),
title = "Sentiment Classification with Bert",
).launch()