Update app.py
Browse files
app.py
CHANGED
@@ -25,23 +25,26 @@ config = AutoConfig.from_pretrained(MODEL)
|
|
25 |
|
26 |
# create classifier function
|
27 |
def classify_compliant(text):
|
28 |
-
|
29 |
-
|
30 |
-
|
31 |
-
|
32 |
-
|
33 |
-
|
|
|
|
|
|
|
34 |
|
35 |
-
|
36 |
-
|
37 |
-
|
38 |
-
|
39 |
|
40 |
|
41 |
-
|
42 |
-
|
43 |
#probs[l] = np.round(float(s), 4)
|
44 |
-
|
45 |
|
46 |
|
47 |
#build the Gradio app
|
|
|
25 |
|
26 |
# create classifier function
|
27 |
def classify_compliant(text):
|
28 |
+
if len(text==0):
|
29 |
+
return "Cannot Categorize the complaint"
|
30 |
+
else:
|
31 |
+
text = cleaned_complaints(text)
|
32 |
+
text = preprocess(text)
|
33 |
+
encoded_input = tokenizer(text, return_tensors='pt')
|
34 |
+
output = model(**encoded_input)
|
35 |
+
scores = output[0][0].detach().numpy()
|
36 |
+
scores = softmax(scores)
|
37 |
|
38 |
+
# Print labels and scores
|
39 |
+
probs = {}
|
40 |
+
ranking = np.argsort(scores)
|
41 |
+
ranking = ranking[::-1]
|
42 |
|
43 |
|
44 |
+
l = config.id2label[ranking[0]]
|
45 |
+
#s = scores[ranking[i]]
|
46 |
#probs[l] = np.round(float(s), 4)
|
47 |
+
return l
|
48 |
|
49 |
|
50 |
#build the Gradio app
|