Created
December 20, 2021 05:55
-
-
Save jcabot/382c617c2cb753e47f23803d05c278e3 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@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