dipesh commited on
Commit
033eb30
1 Parent(s): ec29274
Files changed (1) hide show
  1. app.py +14 -3
app.py CHANGED
@@ -1,9 +1,11 @@
1
  import gradio as gr
2
  import os
3
- os.environ["CUDA_DEVICE_ORDER"]="PCI_BUS_ID"
4
- os.environ["CUDA_VISIBLE_DEVICES"]="0"
 
5
  from transformers import AutoTokenizer, TFAutoModelForSequenceClassification, TextClassificationPipeline
6
 
 
7
  tokenizer = AutoTokenizer.from_pretrained("dipesh/Intent-Classification-Bert-Base-Cased")
8
 
9
  model = TFAutoModelForSequenceClassification.from_pretrained("dipesh/Intent-Classification-Bert-Base-Cased")
@@ -13,8 +15,17 @@ intent_classifier = TextClassificationPipeline(model=model, tokenizer=tokenizer,
13
 
14
 
15
  def predict(input_text):
 
 
 
 
 
 
 
 
16
  ans = intent_classifier(input_text)
17
- return ans[0]['label']
 
18
 
19
 
20
  iface = gr.Interface(fn=predict, inputs="text", outputs="text", title="Intent Classifier",
 
1
  import gradio as gr
2
  import os
3
+
4
+ os.environ["CUDA_DEVICE_ORDER"] = "PCI_BUS_ID"
5
+ os.environ["CUDA_VISIBLE_DEVICES"] = "0"
6
  from transformers import AutoTokenizer, TFAutoModelForSequenceClassification, TextClassificationPipeline
7
 
8
+
9
  tokenizer = AutoTokenizer.from_pretrained("dipesh/Intent-Classification-Bert-Base-Cased")
10
 
11
  model = TFAutoModelForSequenceClassification.from_pretrained("dipesh/Intent-Classification-Bert-Base-Cased")
 
15
 
16
 
17
  def predict(input_text):
18
+ ans = "intent_classifier(input_text)"
19
+ # list of questions words
20
+ question_words = ['will', 'is', 'when', 'may', 'should', 'would', 'which', 'shall', 'does', 'why', 'can', 'whose',
21
+ 'do', 'was', 'where', 'who', 'might', 'how', 'must', 'whom', 'are', 'did', 'were', 'what',
22
+ 'could']
23
+ question_words = set(question_words)
24
+ if ans.split()[0] in question_words:
25
+ ans += "?"
26
  ans = intent_classifier(input_text)
27
+
28
+ return ans[0]['label'], ans[0]['score']
29
 
30
 
31
  iface = gr.Interface(fn=predict, inputs="text", outputs="text", title="Intent Classifier",