CoolFace
Apppublic

Saurav21/Sentiment-Analysis

sourceHugging Faceupdated 4y agoView on Hugging Face
0likes
app.py40 linesDownload Raw Back to root
1 2from transformers import AutoTokenizer, AutoModelForSequenceClassification, pipeline3import gradio as gr4 5def text_sentiments(text):6 7  model_name = "distilbert-base-uncased-finetuned-sst-2-english"8  9  model = AutoModelForSequenceClassification.from_pretrained(model_name)10  tokenizer = AutoTokenizer.from_pretrained(model_name)11 12  classifier = pipeline(task= "sentiment-analysis", model = model, tokenizer = tokenizer)13 14  result = classifier(text)15 16  label = result[0]["label"]17  score = result[0]["score"] * 10018 19  return f"Sentiment is : {label} and Confidence is : {score: 0.2f} %"20 21 22gr.Interface(fn = text_sentiments, 23             inputs = gr.inputs.Textbox(label = "Input Text"),24             outputs = gr.outputs.Textbox(),25             title = "Sentiment Classification with Bert",26             ).launch()27 28 29 30 31 32 33 34 35 36 37 38 39 40