miteshkotak7 commited on
Commit
5f563cd
1 Parent(s): 4716fa7

removed custom inferencing

Browse files
Files changed (2) hide show
  1. code/inference.py +0 -74
  2. code/requirements.txt +0 -1
code/inference.py DELETED
@@ -1,74 +0,0 @@
1
- import json
2
-
3
- from typing import Dict, List, Any
4
- from setfit import SetFitModel
5
-
6
- def model_fn(model_dir):
7
- # load model
8
- model = SetFitModel.from_pretrained(model_dir)
9
-
10
- return model
11
-
12
-
13
- def predict_fn(data, setfitModel):
14
- # destruct model and tokenizer
15
- model = setfitModel
16
-
17
- # get inputs
18
- inputs = data.pop("inputs", data)
19
- if isinstance(inputs, str):
20
- inputs = [inputs]
21
-
22
- # exerciselabels
23
- exerciselabels = ['positive experience',
24
- 'power posing',
25
- 'worry vs rumination',
26
- 'self-confidence',
27
- 'negative emotions',
28
- 'sleep',
29
- 'loneliness',
30
- 'imaginary friend',
31
- 'perfectionism',
32
- 'negative self-talk',
33
- 'woop',
34
- 'venting',
35
- 'worry window',
36
- 'act of kindness',
37
- 'blowing balloons',
38
- 'feeling on anger',
39
- 'power of smile',
40
- 'body scan',
41
- 'stress enhancing thoughts',
42
- 'anger ball of fire',
43
- 'emotions',
44
- 'lean against wall',
45
- 'breathing',
46
- 'crossed arms']
47
-
48
- # run normal prediction
49
- # preds = model.predict(inputs)
50
- preds = model.predict(inputs) #gives predicted label with highest prob
51
- scores = model.predict_proba(inputs)
52
-
53
- # Show predicted exercise, requires you to have stored the 'exerciselabels' somewhere
54
- label = [[el for el, p in zip(exerciselabels, ps) if p] for ps in preds]
55
-
56
- # Modify the label array
57
- modified_label = label[0]
58
-
59
- # Extract the positives probabilities from each inner array
60
- modified_proba = [[inner[0][1]] for item, inner in zip(scores, scores)]
61
-
62
-
63
- score = [[el for el, p in zip(modified_proba, ps) if p] for ps in preds]
64
-
65
- # Modify the score array
66
- modified_score = score[0]
67
-
68
- # Use zip to combine corresponding elements from both arrays
69
- # combined_array = list(zip(modified_label, modified_score))
70
-
71
- combined_dict = [{key: value for key, value in zip(modified_label, modified_score)}]
72
-
73
- # for element in combined_array:
74
- return preds
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
code/requirements.txt DELETED
@@ -1 +0,0 @@
1
- setfit==0.3.0