Heroku H20 H10 when trying to use BERT for QA

  flask, nlp, python

I am trying to use the ‘bert-base-cased’ for QA tasks and integrate it in flask. I have no trouble running the python code, which is

from transformers import pipeline, AutoConfig, AutoModel

model = AutoModel.from_pretrained('bert-base-cased')
nlp = pipeline('question-answering')

def answer_que(questt, anss):

    print(nlp({
    'question': questt,
    'context': anss
}))

..but I am struggling to connect it with flask

def index():
  
    if request.method == 'POST':
      form = request.form
      result = []

      paragra = form['paragraph']
      question = form['question']

      result.append(form['question'])
      result.append(answer_que(question, paragra))
      result.append(form['paragraph'])

      return render_template("index.html",result = result)

    return render_template("index.html")

It seems to crash the system. Deployment is okay, but the website will never load. I tried changing the port as suggested in similar questions but with no luck.

Source: Python Questions

LEAVE A COMMENT