Pavan97 commited on
Commit
cead47b
·
1 Parent(s): bfc7bab

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +6 -5
app.py CHANGED
@@ -4,16 +4,17 @@ 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
 
@@ -21,7 +22,7 @@ def predict(text):
21
 
22
  iface = gr.Interface(fn = predict,
23
  inputs = "text",
24
- outputs = ['text'],
25
  title = 'Emotion Analysis',
26
  description = "Get the emotion of the input text",)
27
 
 
4
 
5
  pipe = pipeline("text-classification", model = "Pavan97/Emotion_Analysis" )
6
  def predict(text):
7
+
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
+
16
+ predicted_labels[id2label[str(idx)]] = label.numpy().item()
17
+
18
 
19
  predicted_labels.sort(key = lambda label: label[1], reverse = True)
20
 
 
22
 
23
  iface = gr.Interface(fn = predict,
24
  inputs = "text",
25
+ outputs = gr.outputs.Label(num_top_classes=5),
26
  title = 'Emotion Analysis',
27
  description = "Get the emotion of the input text",)
28