Spaces:
Sleeping
Sleeping
Create app.py
Browse files
app.py
ADDED
|
@@ -0,0 +1,26 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from transformers import pipeline
|
| 2 |
+
from transformers import AutoTokenizer, AutoModelForSequenceClassification
|
| 3 |
+
|
| 4 |
+
id2label = { 0: "sadness", 1:"joy", 2:"love", 3:"anger", 4:"fear", 5:"surprise" }
|
| 5 |
+
label2id = { "sadness":0, "joy":1, "love":2, "anger":3, "fear":4, "surprise":5}
|
| 6 |
+
|
| 7 |
+
|
| 8 |
+
tokenizer = AutoTokenizer.from_pretrained('bert-base-uncased')
|
| 9 |
+
model = AutoModelForSequenceClassification.from_pretrained("Sadiksha/sentiment_analysis_bert", id2label=id2label, label2id=label2id)
|
| 10 |
+
pipe = pipeline('sentiment-analysis', model = model, tokenizer=tokenizer)
|
| 11 |
+
|
| 12 |
+
|
| 13 |
+
import gradio as gr
|
| 14 |
+
def predict(text):
|
| 15 |
+
return pipe(text)[0]['label']
|
| 16 |
+
|
| 17 |
+
iface = gr.Interface(
|
| 18 |
+
fn=predict,
|
| 19 |
+
inputs='text',
|
| 20 |
+
outputs='text',
|
| 21 |
+
examples=[["I just received an unexpected gift from my friend and it made my day!"],
|
| 22 |
+
["I am feeling so lonely without my family around during the holidays."],
|
| 23 |
+
["I have a fear of spiders, they give me the creeps."]]
|
| 24 |
+
)
|
| 25 |
+
|
| 26 |
+
iface.launch()
|