Spaces:
Sleeping
Sleeping
| from transformers import pipeline | |
| from transformers import AutoTokenizer, AutoModelForSequenceClassification | |
| id2label = { 0: "sadness", 1:"joy", 2:"love", 3:"anger", 4:"fear", 5:"surprise" } | |
| label2id = { "sadness":0, "joy":1, "love":2, "anger":3, "fear":4, "surprise":5} | |
| tokenizer = AutoTokenizer.from_pretrained('bert-base-uncased') | |
| model = AutoModelForSequenceClassification.from_pretrained("Sadiksha/sentiment_analysis_bert", id2label=id2label, label2id=label2id) | |
| pipe = pipeline('sentiment-analysis', model = model, tokenizer=tokenizer) | |
| import gradio as gr | |
| def predict(text): | |
| return pipe(text)[0]['label'] | |
| iface = gr.Interface( | |
| fn=predict, | |
| inputs='text', | |
| outputs='text', | |
| examples=[["I just received an unexpected gift from my friend and it made my day!"], | |
| ["I am feeling so lonely without my family around during the holidays."], | |
| ["I have a fear of spiders, they give me the creeps."]] | |
| ) | |
| iface.launch() |