Exemplo n.º 1
0
def import_csv(json_file, botId):
    file = json_file
    #filename = json_file.filename
    print("File Name", file.filename)
    file.save(os.path.join(UPLOAD_FOLDER, file.filename))
    print("File saved to folder")
    # return redirect(url_for('stories_blueprint.fileupload', filename=filename))
    csvfile = open(UPLOAD_FOLDER + '/' + file.filename,
                   'r',
                   encoding='utf-8',
                   errors='ignore')
    reader = csv.DictReader(csvfile)
    # print(reader)
    header = ["Question", "Answer"]
    for each in reader:
        row = {}
        for field in header:
            row[field] = each[field]
            trainingData = []
            trainingData.append({'text': row['Question'], 'entities': " "})
        csvStories = Intent(name=row['Question'],
                            intentId='fileUpload',
                            userDefined='true',
                            apiTrigger=False,
                            speechResponse=row['Answer'],
                            trainingData=trainingData,
                            botId=botId)

        csvStories.save()
Exemplo n.º 2
0
def import_json(json_file):
    json_data = json_file.read()
    # intents = Intent.objects.from_json(json_data)
    intents = loads(json_data)

    creates_intents = []
    for intent in intents:
        new_intent = Intent()
        new_intent = update_document(new_intent, intent)
        new_intent.save()
        creates_intents.append(new_intent)
    return creates_intents
Exemplo n.º 3
0
def import_json(json_file, botId):
    print("in json_file")
    json_data = json_file.read()
    print(json_data)
    # intents = Intent.objects.from_json(json_data)
    import json
    intents = json.loads(json_data)

    creates_intents = []
    for intent in intents:
        new_intent = Intent()
        new_intent = update_document(new_intent, intent)
        new_intent.save()
        creates_intents.append(new_intent)
    return creates_intents
Exemplo n.º 4
0
def create_intent():
    """
    Create a story from the provided json
    :param json:
    :return:
    """
    content = request.get_json(silent=True)

    intent = Intent()
    intent.name = content.get("name")
    intent.intentId = content.get("intentId")
    intent.speechResponse = content.get("speechResponse")
    intent.trainingData = []

    if content.get("apiTrigger") is True:
        intent.apiTrigger = True
        api_details = ApiDetails()
        isJson = content.get("apiDetails").get("isJson")
        api_details.isJson = isJson
        if isJson:
            api_details.jsonData = content.get("apiDetails").get("jsonData")

        api_details.url = content.get("apiDetails").get("url")
        api_details.headers = content.get("apiDetails").get("headers")
        api_details.requestType = content.get("apiDetails").get("requestType")
        intent.apiDetails = api_details
    else:
        intent.apiTrigger = False

    if content.get("parameters"):
        for param in content.get("parameters"):
            parameter = Parameter()
            update_document(parameter, param)
            intent.parameters.append(parameter)
    try:
        story_id = intent.save()
    except Exception as e:
        return build_response.build_json({"error": str(e)})

    return build_response.build_json({
        "_id": str(story_id.id)
    })