def runReload():
    try:
        kbid = json.loads(request.data)['kbid']
        print(kbid)

        SessionManager.deleteModelSessionByKbid(kbid)
        SentenceSemanticService.define_placeholders()
        SentenceSemanticService.loadTrainedDataStoreSession(kbid)
        return jsonify({"status": "success"})
    except Exception as e:
        return jsonify({"status": "failure"})
Exemple #2
0
def runReload(): # reload api for reloading model
    try:
        logger.info("In runReload Method reloading Model with reload api")
        kbid = json.loads(request.data)['kbid']
        logger.info("Request for Kd id :"+str(kbid))
        if SessionManager.getModelSessionByKbid(kbid):
            SessionManager.deleteModelSessionByKbid(kbid)
        SentenceSemanticService.define_placeholders()
        SentenceSemanticService.loadTrainedDataStoreSession(kbid)
        return jsonify({"status": "success", "message": "Model Reloaded Sucessfully"}), 200
    except Exception as e:
        logger.error("Issue While Reloading Model ! Please Try in Sometime"+str(e))
        return jsonify({"status": "failure", "message": "Issue While Reloading Model ! Please Try in Sometime"}), 500
Exemple #3
0
def runPrediction(): # prediction api
    try:
        logger.info("In Predict Method start")
        userQuery = json.loads(request.data)['question'].lower()
        kbid = json.loads(request.data)['kb_id']
        topN = json.loads(request.data)['top_n']
        logger.info("Question : "+str(userQuery))

        if not SessionManager.getModelSessionByKbid(kbid):
            SentenceSemanticService.define_placeholders()
        try:
            SentenceSemanticService.loadTrainedDataStoreSession(kbid)
            # userQuery = 'How many online surveys can I participate'
            matched_statement = SentenceSemanticService.process(userQuery=userQuery, kbid=kbid, topN=topN)
            logger.info("Matching Statement is :" + str(matched_statement))

            result = []
            for match_question, matched_score, question_id, answer in matched_statement:
                result.append(
                    {"matched_question_id": question_id, "matched_question": match_question, "score": str(matched_score),"answer": answer})
            return jsonify(result),200
        except Exception as e:
            return jsonify(
                {"status": "failure", "message": "Issue While Reloading Model ! Please Try in Sometime"}), 500
            logger.info("runPrediction: Error while reloading the model : " + str(e))

    except Exception as e:
        logger.info("Error : "+str(e))
        return jsonify({"message": "Service Not Found ! Please Try After Sometime", "status": "failed"}), 404
def runPrediction():
    try:
        userQuery = json.loads(request.data)['question']
        kbid = json.loads(request.data)['kb_id']
        topN = json.loads(request.data)['top_n']
        print(userQuery)
        print(kbid)

        if not SessionManager.getModelSessionByKbid(kbid):
            SentenceSemanticService.define_placeholders()

        SentenceSemanticService.loadTrainedDataStoreSession(kbid)
        # userQuery = 'How many online surveys can I participate'
        matched_statement = SentenceSemanticService.process(userQuery=userQuery, kbid=kbid, topN=topN)
        print(matched_statement)

        result = []
        for match_question, matched_score, question_id, answer in matched_statement:
            result.append(
                {"matched_question_id": question_id, "matched_question": match_question, "score": str(matched_score),
                 "answer": answer})

        return jsonify(result)


    except Exception as e:
        print(e)
Exemple #5
0
    def loadTrainedDataStoreSession(cls, kbid):
        is_model_loaded = SessionManager.getModelSessionByKbid(kbid)

        if not is_model_loaded:
            try:
                unique_data_list = DBUtil.getData('kb_qna', {'kb_id': kbid})
                unique_statement_list = cls.create_only_statements_list(
                    unique_data_list)
                customer_embed = cls.embed_customer_data(unique_statement_list)
                embeding_dict = {
                    "unique_data_with_model": unique_data_list,
                    "unique_statement_list": unique_statement_list,
                    "customer_embed": customer_embed
                }
                SessionManager.setModelSessionByKbid(
                    kbid=kbid, model_session=embeding_dict)
                print('Confidence Checker Model Restored for Customer : ' +
                      str(kbid))

            except Exception as e:
                print('Confidence Checker Model Not Restored for Customer : ' +
                      str(e))
Exemple #6
0
 def getModelSession(cls, kbid):  #get model sessio n from SessionManager
     customerModelSession = SessionManager.getModelSessionByKbid(kbid)
     return customerModelSession
Exemple #7
0
 def getModelSession(cls, kbid):
     customerModelSession = SessionManager.getModelSessionByKbid(kbid)
     return customerModelSession