Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -3,8 +3,21 @@ import gradio as gr
|
|
| 3 |
from transformers import pipeline
|
| 4 |
|
| 5 |
pipe = pipeline("text-classification", model = "Pavan97/Emotion_Analysis" )
|
| 6 |
-
def predict(
|
| 7 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 8 |
|
| 9 |
iface = gr.Interface(fn = predict,
|
| 10 |
inputs = "text",
|
|
|
|
| 3 |
from transformers import pipeline
|
| 4 |
|
| 5 |
pipe = pipeline("text-classification", model = "Pavan97/Emotion_Analysis" )
|
| 6 |
+
def predict(text):
|
| 7 |
+
threshold=1e-2
|
| 8 |
+
tokenized_text = tokenizer(text, return_tensors = 'pt')
|
| 9 |
+
with torch.no_grad():
|
| 10 |
+
labels = model(**tokenized_text)
|
| 11 |
+
labels = torch.nn.functional.softmax(labels.logits[0], dim = -1)
|
| 12 |
+
|
| 13 |
+
predicted_labels = []
|
| 14 |
+
for idx, label in enumerate(labels):
|
| 15 |
+
if label > threshold:
|
| 16 |
+
predicted_labels.append((id2label[str(idx)], label.numpy().item()))
|
| 17 |
+
|
| 18 |
+
predicted_labels.sort(key = lambda label: label[1], reverse = True)
|
| 19 |
+
|
| 20 |
+
return predicted_labels
|
| 21 |
|
| 22 |
iface = gr.Interface(fn = predict,
|
| 23 |
inputs = "text",
|