CoolFace
Apppublic

csvaldellon/qa_model

sourceHugging Faceupdated 3y agoView on Hugging Face
0likes
main.py46 linesDownload Raw Back to app
1import uvicorn2from fastapi import FastAPI, Request3from .utils import QASearcher4 5app = FastAPI()6qa_search = QASearcher()7 8@app.post("/set_context")9async def set_context(data: Request):10    """11    Fastapi POST method that sets the QA context for search.12 13    Args:14      data(`dict`): Two fields required 'questions' (`list` of `str`)15        and 'answers' (`list` of `str`)16    """17    data = await data.json()18 19    qa_search.set_context_qa(data["questions"], data["answers"])20    return {"message": "Search context set"}21 22 23@app.post("/get_answer")24async def get_answer(data: Request):25    """26    Fastapi POST method that gets the best question and answer27    in the set context.28 29    Args:30      data(`dict`): One field required 'questions' (`list` of `str`)31 32    Returns:33      A `dict` containing the original question ('orig_q'), the most similar34      question in the context ('best_q') and the associated answer ('best_a').35    """36    data = await data.json()37 38    response = qa_search.get_answers(data["questions"], batch=1)39    return response40 41 42# # initialises the QA model and starts the uvicorn app43# if __name__ == "__main__":44    45#     uvicorn.run(app, host="0.0.0.0", port=8000)46