lunadebruyne commited on
Commit
9ef6ad9
·
1 Parent(s): bd33424

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +15 -3
app.py CHANGED
@@ -23,6 +23,18 @@ def inference_sentence(text):
23
  predicted_class_id = logits.argmax().item()
24
  output = model.config.id2label[predicted_class_id]
25
  return output
 
 
 
 
 
 
 
 
 
 
 
 
26
 
27
  def inference_dataset(file_object, option_list):
28
  tokenizer = AutoTokenizer.from_pretrained(inference_modelpath)
@@ -48,9 +60,9 @@ def inference_dataset(file_object, option_list):
48
  f.write(str(line[0]) + '\t' + str(line[1]) + '\t' + str(line[2]) + '\n')
49
  f.close()
50
  output1 = output
51
- output2 = output3 = output4 = output5 = "This option was not selected."
52
  if "emotion frequencies" in option_list:
53
- output2 = "This option was selected."
54
  if "emotion distribution over time" in option_list:
55
  output3 = "This option was selected."
56
  if "peaks" in option_list:
@@ -81,7 +93,7 @@ iface_dataset = gr.Interface(
81
  outputs = [
82
  #gr.Textbox(label="Output file"),
83
  "file",
84
- gr.Textbox(label="Emotion frequencies"),
85
  gr.Textbox(label="Emotion distribution over time"),
86
  gr.Textbox(label="Peaks"),
87
  gr.Textbox(label="Topics")
 
23
  predicted_class_id = logits.argmax().item()
24
  output = model.config.id2label[predicted_class_id]
25
  return output
26
+
27
+ def frequencies(preds):
28
+ preds_dict = {"neutral": 0, "anger": 0, "fear": 0, "joy": 0, "love": 0, "sadness": 0}
29
+ for pred in preds:
30
+ preds_dict[pred] = preds_dict[pred] + 1
31
+ x = list(preds_dict.keys())
32
+ labels = list(preds_dict.values())
33
+
34
+ fig, ax = plt.subplots(figsize=(6, 6))
35
+ ax.pie(x, labels=labels, autopct='%.1f%%')
36
+ ax.set_title('Emotion frequencies')
37
+ return plt.tight_layout()
38
 
39
  def inference_dataset(file_object, option_list):
40
  tokenizer = AutoTokenizer.from_pretrained(inference_modelpath)
 
60
  f.write(str(line[0]) + '\t' + str(line[1]) + '\t' + str(line[2]) + '\n')
61
  f.close()
62
  output1 = output
63
+ output3 = output4 = output5 = "This option was not selected."
64
  if "emotion frequencies" in option_list:
65
+ output2 = frequencies(preds)
66
  if "emotion distribution over time" in option_list:
67
  output3 = "This option was selected."
68
  if "peaks" in option_list:
 
93
  outputs = [
94
  #gr.Textbox(label="Output file"),
95
  "file",
96
+ gr.Plot(label="Emotion frequencies"),
97
  gr.Textbox(label="Emotion distribution over time"),
98
  gr.Textbox(label="Peaks"),
99
  gr.Textbox(label="Topics")