Skip to content

Instantly share code, notes, and snippets.

@jcabot
Created December 20, 2021 05:55
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jcabot/382c617c2cb753e47f23803d05c278e3 to your computer and use it in GitHub Desktop.
Save jcabot/382c617c2cb753e47f23803d05c278e3 to your computer and use it in GitHub Desktop.
@app.route('/ask_QA')
def ask_QA():
query = request.args.get('question')
print("Question received: ", query)
# Connect to Elasticsearch (locally installed)
document_store = ElasticsearchDocumentStore(host="localhost", username="", password="", index="blogposts")
retriever = ElasticsearchRetriever(document_store=document_store)
reader = FARMReader(model_name_or_path="deepset/roberta-base-squad2", use_gpu=True)
from haystack.pipelines import ExtractiveQAPipeline
pipe = ExtractiveQAPipeline(reader, retriever)
# Voilà! Ask a question!
prediction = pipe.run(
query, params={"Retriever": {"top_k": 5}, "Reader": {"top_k": 3}}
)
# Now you can either print the object directly
print("\n\nRaw object:\n")
pprint(prediction)
headers: Dict[str, str] = {"Content-Type": "application/json"}
return make_response(
prediction,
200,
headers)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment