create app.py
Browse files
app.py
ADDED
@@ -0,0 +1,24 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import gradio as gr
|
2 |
+
from transformes import pipeline
|
3 |
+
|
4 |
+
model_id = "Subhajit01/distilbert-base-uncased-finetuned-emotion"
|
5 |
+
classifier = pipeline("text-classification", model=model_id)
|
6 |
+
labels = ['sadness', 'joy', 'love', 'anger', 'fear', 'surprise']
|
7 |
+
|
8 |
+
def predict(text):
|
9 |
+
max_prob_id = 0
|
10 |
+
max_prob = 0
|
11 |
+
preds = classifier(text, return_all_scores=True)
|
12 |
+
for i in range(len(preds[0])):
|
13 |
+
if (preds[0][i]["score"] > max_prob):
|
14 |
+
max_prob = preds[0][i]["score"]
|
15 |
+
max_prob_id = i
|
16 |
+
return labels[max_prob_id]
|
17 |
+
|
18 |
+
iface = gr.Interface(fn=predict,
|
19 |
+
inputs="text",
|
20 |
+
outputs="text",
|
21 |
+
title="Sentiment Analyzer",
|
22 |
+
description="Enter text to analyze its sentiment.")
|
23 |
+
|
24 |
+
iface.launch()
|