saritha5 commited on
Commit
51faed1
1 Parent(s): ab81fdf

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +16 -13
app.py CHANGED
@@ -25,23 +25,26 @@ config = AutoConfig.from_pretrained(MODEL)
25
 
26
  # create classifier function
27
  def classify_compliant(text):
28
- text = cleaned_complaints(text)
29
- text = preprocess(text)
30
- encoded_input = tokenizer(text, return_tensors='pt')
31
- output = model(**encoded_input)
32
- scores = output[0][0].detach().numpy()
33
- scores = softmax(scores)
 
 
 
34
 
35
- # Print labels and scores
36
- probs = {}
37
- ranking = np.argsort(scores)
38
- ranking = ranking[::-1]
39
 
40
 
41
- l = config.id2label[ranking[0]]
42
- #s = scores[ranking[i]]
43
  #probs[l] = np.round(float(s), 4)
44
- return l
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