luminoso_api/v5_upload.py
def create_project_with_docs(
    client, docs, language, name, account=None, progress=False
):
    """
    Given an iterator of documents, upload them as a Luminoso project.
    """
    description = 'Uploaded using lumi-upload at {}'.format(time.asctime())
    if account is not None:
        proj_record = client.post(
            'projects',
            name=name,
            language=language,
            description=description,
            account_id=account,
        )
    else:
        proj_record = client.post(
            'projects', name=name, language=language, description=description
        )
    proj_id = proj_record['project_id']
    proj_client = client.client_for_path('projects/' + proj_id)
    try:
        if progress:
            progress_bar = tqdm(desc='Uploading documents')
        else:
            progress_bar = None

        for batch in _batches(docs, BATCH_SIZE):
            docs_to_upload = [_simplify_doc(doc) for doc in batch]
            proj_client.post('upload', docs=docs_to_upload)
            if progress:
                progress_bar.update(BATCH_SIZE)

    finally:
        if progress:
            progress_bar.close()

    print('The server is building project {!r}.'.format(proj_id))
    proj_client.post('build')

    while True:
        time.sleep(10)
        proj_status = proj_client.get()
        build_info = proj_status['last_build_info']
        if 'success' in build_info:
            if not build_info['success']:
                raise LuminosoServerError(build_info['reason'])
            return proj_status
def create_project_with_docs(
    client, docs, language, name, account=None, progress=False
):
    """
    Given an iterator of documents, upload them as a Luminoso project.
    """
    description = 'Uploaded using lumi-upload at {}'.format(time.asctime())
    if account is not None:
        proj_record = client.post(
            'projects',
            name=name,
            language=language,
            description=description,
            account_id=account,
        )
    else:
        proj_record = client.post(
            'projects', name=name, language=language, description=description
        )
    proj_id = proj_record['project_id']
    proj_client = client.client_for_path('projects/' + proj_id)
    try:
        if progress:
            progress_bar = tqdm(desc='Uploading documents')
        else:
            progress_bar = None

        for batch in _batches(docs, BATCH_SIZE):
            docs_to_upload = [_simplify_doc(doc) for doc in batch]
            proj_client.post('upload', docs=docs_to_upload)
            if progress:
                progress_bar.update(BATCH_SIZE)

    finally:
        if progress:
            progress_bar.close()

    print('The server is building project {!r}.'.format(proj_id))
    proj_client.post('build')

    while True:
        time.sleep(10)
        proj_status = proj_client.get()
        build_info = proj_status['last_build_info']
        if 'success' in build_info:
            if not build_info['success']:
                raise LuminosoServerError(build_info['reason'])
            return proj_status
Given an iterator of documents, upload them as a Luminoso project.