Henok21 commited on
Commit
e24d9ff
·
1 Parent(s): 792440a

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +5 -16
app.py CHANGED
@@ -39,9 +39,6 @@ config.id2label = {0: 'NEGATIVE', 1: 'NEUTRAL', 2: 'POSITIVE'}
39
  config.label2id = {"NEGATIVE": 0, "NEUTRAL": 1, "POSITIVE": 2}
40
 
41
  # creating a function used for gradio app
42
- # Creating dictionary
43
- dictionary = {}
44
-
45
  def sentiment_analysis(text):
46
 
47
  # Encode the text using the tokenizer
@@ -52,21 +49,13 @@ def sentiment_analysis(text):
52
  # Your code to get the scores for each class
53
  scores = output[0][0].detach().numpy()
54
  scores = softmax(scores)
55
-
56
- # Convert the numpy array into a list
57
- scores = scores.tolist()
58
- ranking = np.argsort(scores)
59
- ranking = ranking[::-1]
60
-
61
- for i in range(len(scores)):
62
- l = config.id2label[ranking[i]]
63
- s = scores[ranking[i]]
64
-
65
- # Convert the numpy float32 object into a float
66
- dictionary[l] = float(s)
67
 
68
  # Return the dictionary as the response content
69
- return dictionary
70
 
71
  # Create your interface
72
  demo = gr.Interface(
 
39
  config.label2id = {"NEGATIVE": 0, "NEUTRAL": 1, "POSITIVE": 2}
40
 
41
  # creating a function used for gradio app
 
 
 
42
  def sentiment_analysis(text):
43
 
44
  # Encode the text using the tokenizer
 
49
  # Your code to get the scores for each class
50
  scores = output[0][0].detach().numpy()
51
  scores = softmax(scores)
52
+
53
+ labels = {0: "NEGAITVE", 1: "NEUTRAL", 2: "POSITIVE"}
54
+ scores = {labels[i] float(s) for i , s in enumerate(scores) }
55
+
 
 
 
 
 
 
 
 
56
 
57
  # Return the dictionary as the response content
58
+ return scores
59
 
60
  # Create your interface
61
  demo = gr.Interface(