sergeyfeldman commited on
Commit
ac68060
·
1 Parent(s): 23c58d5

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +14 -2
app.py CHANGED
@@ -13,8 +13,20 @@ all_label_names = list(model.config.id2label.values())
13
 
14
  def predict(text):
15
  probs = expit(model(**tokenizer([text], return_tensors="pt", padding=True)).logits.detach().numpy())
16
- d = {i: float(np.round(j, 2)) for i, j in zip(all_label_names, probs[0])}
17
- print(d)
 
 
 
 
 
 
 
 
 
 
 
 
18
  return d
19
 
20
  iface = gr.Interface(
 
13
 
14
  def predict(text):
15
  probs = expit(model(**tokenizer([text], return_tensors="pt", padding=True)).logits.detach().numpy())
16
+ # can't use numpy for whatever reason
17
+ probs = [float(np.round(i, 2)) for i in probs[0]]
18
+ # break out issue, harm, sentiment, feeling
19
+ zipped_list = list(zip(all_label_names, probs))
20
+ issues = [(i, j) for i, j in zipped_list if i.startswith('issue')]
21
+ feelings = [(i, j) for i, j in zipped_list if i.startswith('feeling')]
22
+ harm = [(i, j) for i, j in zipped_list if i.startswith('harm')]
23
+ # keep tops for each one
24
+ issues = sorted(issues)[::-1][:3]
25
+ feelings = sorted(feelings)[::-1][:3]
26
+ harm = sorted(harm)[::-1][:1]
27
+ # top is the combo of these
28
+ top = issues + feelings + harm
29
+ d = {i: j for i, j in harm}
30
  return d
31
 
32
  iface = gr.Interface(