Spaces:
Build error
Build error
Commit
·
50ca014
1
Parent(s):
48c02cd
app.py
CHANGED
@@ -31,27 +31,31 @@ dict_category_answer = {
|
|
31 |
|
32 |
|
33 |
def QA(text):
|
34 |
-
MODEL_NAME = 'cl-tohoku/bert-base-japanese-whole-word-masking'
|
35 |
-
bert_sc = BertForSequenceClassification.from_pretrained("/saved_model")
|
36 |
-
|
37 |
-
tokenizer = BertJapaneseTokenizer.from_pretrained(
|
38 |
-
MODEL_NAME,
|
39 |
-
model_max_length = 200,
|
40 |
-
padding_side="right"
|
41 |
-
)
|
42 |
-
|
43 |
-
question_classifier = pipeline(
|
44 |
-
"text-classification",
|
45 |
-
model=bert_sc.to("cpu"),
|
46 |
-
tokenizer=tokenizer
|
47 |
-
)
|
48 |
-
|
49 |
-
predicted_output = question_classifier(text)
|
50 |
-
predicted_label = predicted_output[0]['label']
|
51 |
-
|
52 |
-
answer_text = dict_category_answer[predicted_label]
|
53 |
|
54 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
55 |
|
56 |
demo = gr.Interface(fn=QA, inputs="text", outputs="text")
|
57 |
|
|
|
31 |
|
32 |
|
33 |
def QA(text):
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
34 |
|
35 |
+
try:
|
36 |
+
MODEL_NAME = 'cl-tohoku/bert-base-japanese-whole-word-masking'
|
37 |
+
bert_sc = BertForSequenceClassification.from_pretrained("/saved_model")
|
38 |
+
|
39 |
+
tokenizer = BertJapaneseTokenizer.from_pretrained(
|
40 |
+
MODEL_NAME,
|
41 |
+
model_max_length = 200,
|
42 |
+
padding_side="right"
|
43 |
+
)
|
44 |
+
|
45 |
+
question_classifier = pipeline(
|
46 |
+
"text-classification",
|
47 |
+
model=bert_sc.to("cpu"),
|
48 |
+
tokenizer=tokenizer
|
49 |
+
)
|
50 |
+
|
51 |
+
predicted_output = question_classifier(text)
|
52 |
+
predicted_label = predicted_output[0]['label']
|
53 |
+
|
54 |
+
answer_text = dict_category_answer[predicted_label]
|
55 |
+
except e:
|
56 |
+
return str(e)
|
57 |
+
|
58 |
+
return "error occured"
|
59 |
|
60 |
demo = gr.Interface(fn=QA, inputs="text", outputs="text")
|
61 |
|