salsarra commited on
Commit
bc1962f
·
verified ·
1 Parent(s): fbdbb37

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +14 -0
app.py CHANGED
@@ -39,6 +39,20 @@ beto_sqac_model_spanish = 'salsarra/Beto-Spanish-Cased-SQAC'
39
  beto_sqac_model_spanish_qa = TFAutoModelForQuestionAnswering.from_pretrained(beto_sqac_model_spanish)
40
  beto_sqac_tokenizer_spanish = AutoTokenizer.from_pretrained(beto_sqac_model_spanish)
41
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
42
  # Define error handling to separate input size errors from other issues
43
  def handle_error_message(e, default_limit=512):
44
  error_message = str(e)
 
39
  beto_sqac_model_spanish_qa = TFAutoModelForQuestionAnswering.from_pretrained(beto_sqac_model_spanish)
40
  beto_sqac_tokenizer_spanish = AutoTokenizer.from_pretrained(beto_sqac_model_spanish)
41
 
42
+ # Define question_answering_v1 for ConfliBERT English
43
+ def question_answering_v1(context, question):
44
+ try:
45
+ inputs = qa_tokenizer_v1(question, context, return_tensors='tf', truncation=True)
46
+ outputs = qa_model_v1(inputs)
47
+ answer_start = tf.argmax(outputs.start_logits, axis=1).numpy()[0]
48
+ answer_end = tf.argmax(outputs.end_logits, axis=1).numpy()[0] + 1
49
+ answer = qa_tokenizer_v1.convert_tokens_to_string(
50
+ qa_tokenizer_v1.convert_ids_to_tokens(inputs['input_ids'].numpy()[0][answer_start:answer_end])
51
+ )
52
+ return f"<span style='color: green; font-weight: bold;'>{answer}</span>"
53
+ except Exception as e:
54
+ return handle_error_message(e)
55
+
56
  # Define error handling to separate input size errors from other issues
57
  def handle_error_message(e, default_limit=512):
58
  error_message = str(e)