Exemplo n.º 1
0
def perform_colab_commit(project, privacy):
    # file_id, project, privacy api key
    file_id = get_colab_file_id()
    if file_id is None:
        log("Colab File Id is not provided", error=True)

    # /gist/colab-commit data = {file_id, project}, return status
    if '/' not in project:
        project = get_current_user()['username'] + '/' + project

    data = {'project': project, 'file_id': file_id, 'visibility': privacy}

    if privacy == 'auto':
        data['public'] = True
    elif privacy == 'secret' or privacy == 'private':
        data['public'] = False

    auth_headers = _h()

    log("Uploading colab notebook to Jovian...")
    res = post(url=_u('/gist/colab-commit'),
               data=data,
               headers=auth_headers)

    if res.status_code == 200:
        return res.json()['data']
    raise ApiError('Colab commit failed: ' + pretty(res))
Exemplo n.º 2
0
def perform_colab_commit(project, privacy):
    if '/' not in project:
        project = get_current_user()['username'] + '/' + project

    data = {
        'project': project,
        'file_id': get_colab_file_id(),
        'visibility': privacy
    }

    if privacy == 'auto':
        data['public'] = True
    elif privacy == 'secret' or privacy == 'private':
        data['public'] = False

    auth_headers = _h()

    log("Uploading colab notebook to Jovian...")
    res = post(url=_u('/gist/colab-commit'), data=data, headers=auth_headers)

    if res.status_code == 200:
        data, warning = parse_success_response(res)
        if warning:
            log(warning, error=True)
        return data
    raise ApiError('Colab commit failed: ' + pretty(res))
Exemplo n.º 3
0
def test_h():
    with fake_creds('.jovian', 'credentials.json'):
        expected_result = {
            "Authorization": "Bearer fake_api_key",
            "x-jovian-source": "library",
            "x-jovian-library-version": __version__,
            "x-jovian-guest": "b6538d4dfde04fcf993463a828a9cec6",
            "x-jovian-org": "staging"
        }

        assert _h() == expected_result
Exemplo n.º 4
0
def submit(assignment=None, notebook_url=None, **kwargs):
    """ Performs jovian.commit and makes a assignment submission with the uploaded notebook.
    """
    if not assignment:
        log("Please provide assignment name", error=True)
        return

    filename = _parse_filename(kwargs.get('filename'))
    if filename == '__notebook_source__.ipynb':
        log("""jovian.submit does not support kaggle notebooks directly.
         Please make a commit first, copy the notebook URL and pass it to jovian.submit.
         eg. jovian.submit(assignment="zero-to-pandas-a1", 
                           notebook_url="https://jovian.ai/PrajwalPrashanth/assignment")""", error=True)
        return

    post_url = POST_API.format(assignment)
    nb_url = notebook_url if notebook_url else commit(**kwargs)

    if nb_url:
        data = {
            'assignment_url': nb_url
        }
        auth_headers = _h()

        log('Submitting assignment..')
        res = post(url=_u(post_url),
                   json=data,
                   headers=auth_headers)

        if res.status_code == 200:
            data = res.json()['data']
            course_slug = data.get('course_slug')
            assignment_slug = data.get('section_slug')

            assignment_page_url = ASSIGNMENT_PAGE_URL.format(course_slug, assignment_slug)
            log('Verify your submission at {}'.format(urljoin(read_webapp_url(), assignment_page_url)))
        else:
            log('Jovian submit failed. {}'.format(pretty(res)), error=True)