Пример #1
0
def get_participant_or_host_teams(url):
    """
    Returns the participant or host teams corresponding to the user
    """
    header = get_request_header()

    try:
        response = requests.get(url, headers=header)
        response.raise_for_status()
    except requests.exceptions.HTTPError as err:
        if response.status_code == 401:
            validate_token(response.json())
        echo(style(err, fg="red", bold=True))
        sys.exit(1)
    except requests.exceptions.RequestException:
        echo(
            style(
                "\nCould not establish a connection to EvalAI."
                " Please check the Host URL.\n",
                bold=True,
                fg="red",
            ))
        sys.exit(1)

    response = response.json()

    return response["results"]
Пример #2
0
def get_participant_or_host_team_challenges(url, teams):
    """
    Returns the challenges corresponding to the participant or host teams
    """
    challenges = []
    for team in teams:
        header = get_request_header()
        try:
            response = requests.get(url.format(team["id"]), headers=header)
            response.raise_for_status()
        except requests.exceptions.HTTPError as err:
            if response.status_code == 401:
                validate_token(response.json())
            echo(err)
            sys.exit(1)
        except requests.exceptions.RequestException:
            echo(
                style(
                    "\nCould not establish a connection to EvalAI."
                    " Please check the Host URL.\n",
                    bold=True,
                    fg="red",
                ))
            sys.exit(1)
        response = response.json()
        challenges += response["results"]
    return challenges
Пример #3
0
def display_challenges(url):
    """
    Function to fetch & display the challenge list based on API
    """
    header = get_request_header()
    try:
        response = requests.get(url, headers=header)
        response.raise_for_status()
    except requests.exceptions.HTTPError as err:
        if response.status_code == 401:
            validate_token(response.json())
        echo(err)
        sys.exit(1)
    except requests.exceptions.RequestException:
        echo(
            style(
                "\nCould not establish a connection to EvalAI."
                " Please check the Host URL.\n",
                bold=True,
                fg="red",
            ))
        sys.exit(1)

    response = response.json()

    challenges = response["results"]
    if len(challenges) != 0:
        pretty_print_challenge_data(challenges)
    else:
        echo("Sorry, no challenges found.")
Пример #4
0
def submission_details_request(submission_id):
    """
    Function to request details of a particular submission
    """
    url = "{}{}".format(get_host_url(), URLS.get_submission.value)
    url = url.format(submission_id)
    headers = get_request_header()
    try:
        response = requests.get(url, headers=headers)
        response.raise_for_status()
    except requests.exceptions.HTTPError as err:
        if response.status_code in EVALAI_ERROR_CODES:
            validate_token(response.json())
            echo(
                style(
                    "\nError: {}\n"
                    "\nUse `evalai challenge CHALLENGE phase PHASE submissions` "
                    "to view your submission.\n".format(
                        response.json()["error"]),
                    fg="red",
                    bold=True,
                ))
        else:
            echo(err)
        sys.exit(1)
    except requests.exceptions.RequestException:
        echo(
            style(
                "\nCould not establish a connection to EvalAI."
                " Please check the Host URL.\n",
                bold=True,
                fg="red",
            ))
        sys.exit(1)
    return response
Пример #5
0
def make_submission(challenge_id, phase_id, file, submission_metadata={}):
    """
    Function to submit a file to a challenge
    """
    url = "{}{}".format(get_host_url(), URLS.make_submission.value)
    url = url.format(challenge_id, phase_id)

    headers = get_request_header()
    input_file = {"input_file": file}
    data = {"status": "submitting"}
    data = dict(data, **submission_metadata)

    try:
        response = requests.post(url,
                                 headers=headers,
                                 files=input_file,
                                 data=data)
        file.close()
        response.raise_for_status()
    except requests.exceptions.HTTPError as err:
        if response.status_code in EVALAI_ERROR_CODES:
            validate_token(response.json())
            echo(
                style(
                    "\nError: {}\n"
                    "\nUse `evalai challenges` to fetch the active challenges.\n"
                    "\nUse `evalai challenge CHALLENGE phases` to fetch the "
                    "active phases.\n".format(response.json()["error"]),
                    fg="red",
                    bold=True,
                ))
        else:
            echo(err)
        if "input_file" in response.json():
            echo(style(response.json()["input_file"][0], fg="red", bold=True))
        sys.exit(1)
    except requests.exceptions.RequestException:
        echo(
            style(
                "\nCould not establish a connection to EvalAI."
                " Please check the Host URL.\n",
                bold=True,
                fg="red",
            ))
        sys.exit(1)
    response = response.json()
    echo(
        style(
            "\nYour file {} with the ID {} is successfully submitted.\n".
            format(file.name, response["id"]),
            fg="green",
            bold=True,
        ))
    echo(
        style(
            "You can use `evalai submission {}` to view this submission's status.\n"
            .format(response["id"]),
            bold=True,
            fg="white"))
Пример #6
0
def display_challenge_phase_list(challenge_id):
    """
    Function to display all challenge phases for a particular challenge.
    """
    url = URLS.challenge_phase_list.value
    url = "{}{}".format(get_host_url(), url)
    url = url.format(challenge_id)
    headers = get_request_header()
    try:
        response = requests.get(url, headers=headers)
        response.raise_for_status()
    except requests.exceptions.HTTPError as err:
        if response.status_code in EVALAI_ERROR_CODES:
            validate_token(response.json())
            echo(
                style(
                    "\nError: {}".format(response.json()["error"]),
                    fg="red",
                    bold=True,
                ))
            echo(
                style(
                    "\nUse `evalai challenges` to fetch the active challenges.",
                    fg="red",
                    bold=True,
                ))
            echo(
                style(
                    "\nUse `evalai challenge CHALLENGE phases` to fetch the active phases.\n",
                    fg="red",
                    bold=True,
                ))
        else:
            echo(err)
        sys.exit(1)
    except requests.exceptions.RequestException:
        echo(
            style(
                "\nCould not establish a connection to EvalAI."
                " Please check the Host URL.\n",
                bold=True,
                fg="red",
            ))
        sys.exit(1)

    response = response.json()
    challenge_phases = response["results"]
    pretty_print_all_challenge_phases(challenge_phases)
Пример #7
0
def participate_in_a_challenge(challenge_id, participant_team_id):
    """
    Function to participate in a particular challenge.
    """

    url = "{}{}".format(get_host_url(), URLS.participate_in_a_challenge.value)
    url = url.format(challenge_id, participant_team_id)

    headers = get_request_header()
    headers["Content-Type"] = "application/json"
    try:
        response = requests.post(url, headers=headers)
        response.raise_for_status()
    except requests.exceptions.HTTPError as err:
        if response.status_code in EVALAI_ERROR_CODES:
            validate_token(response.json())
            echo(
                style(
                    "\nError: {}\n"
                    "\nUse `evalai challenges` to fetch the active challenges.\n"
                    "\nUse `evalai teams` to fetch your participant "
                    "teams.\n".format(response.json()["error"]),
                    fg="red",
                    bold=True,
                ))
        else:
            echo(err)
        sys.exit(1)
    except requests.exceptions.RequestException:
        echo(
            style(
                "\nCould not establish a connection to EvalAI."
                " Please check the Host URL.\n",
                bold=True,
                fg="red",
            ))
        sys.exit(1)

    if response.status_code == 201:
        echo(
            style(
                "Your team id {} is now participating in this challenge.".
                format(participant_team_id),
                fg="green",
                bold=True,
            ))
Пример #8
0
def get_submission_meta_attributes(challenge_id, phase_id):
    """
    Function to get all submission_meta_attributes for a challenge phase

    Parameters:
    challenge_id (int): id of challenge to which submission is made
    phase_id (int): id of challenge phase to which submission is made

    Returns:
    list: list of objects of submission meta attributes
    """
    url = "{}{}".format(get_host_url(), URLS.challenge_phase_detail.value)
    url = url.format(challenge_id, phase_id)
    headers = get_request_header()
    try:
        response = requests.get(url, headers=headers)
        response.raise_for_status()
    except requests.exceptions.HTTPError as err:
        if response.status_code in EVALAI_ERROR_CODES:
            validate_token(response.json())
            echo(
                style(
                    "\nError: {}\n"
                    "\nUse `evalai challenges` to fetch the active challenges.\n"
                    "\nUse `evalai challenge CHALLENGE phases` to fetch the "
                    "active phases.\n".format(response.json()),
                    fg="red",
                    bold=True,
                )
            )
        else:
            echo(err)
        sys.exit(1)
    except requests.exceptions.RequestException:
        echo(
            style(
                "\nCould not establish a connection to EvalAI."
                " Please check the Host URL.\n",
                bold=True,
                fg="red",
            )
        )
        sys.exit(1)
    response = response.json()
    return response["submission_meta_attributes"]
Пример #9
0
def display_challenge_phase_detail(challenge_id, phase_id, is_json):
    """
    Function to print details of a challenge phase.
    """
    url = URLS.challenge_phase_detail.value
    url = "{}{}".format(get_host_url(), url)
    url = url.format(challenge_id, phase_id)
    headers = get_request_header()

    try:
        response = requests.get(url, headers=headers)
        response.raise_for_status()
    except requests.exceptions.HTTPError as err:
        if response.status_code in EVALAI_ERROR_CODES:
            validate_token(response.json())
            echo(
                style(
                    "\nError: {}\n"
                    "\nUse `evalai challenges` to fetch the active challenges.\n"
                    "\nUse `evalai challenge CHALLENGE phases` to fetch the "
                    "active phases.\n".format(response.json()["error"]),
                    fg="red",
                    bold=True,
                ))
        else:
            echo(err)
        sys.exit(1)
    except requests.exceptions.RequestException:
        echo(
            style(
                "\nCould not establish a connection to EvalAI."
                " Please check the Host URL.\n",
                bold=True,
                fg="red",
            ))
        sys.exit(1)

    response = response.json()

    phase = response
    if is_json:
        phase_json = json.dumps(phase, indent=4, sort_keys=True)
        echo(phase_json)
    else:
        pretty_print_challenge_phase_data(phase)
Пример #10
0
def display_ongoing_challenge_list():
    """
    Displays the list of ongoing challenges from the backend
    """
    url = "{}{}".format(get_host_url(), URLS.challenge_list.value)

    header = get_request_header()
    try:
        response = requests.get(url, headers=header)
        response.raise_for_status()
    except requests.exceptions.HTTPError as err:
        if response.status_code == 401:
            validate_token(response.json())
        echo(style(err, fg="red", bold=True))
        sys.exit(1)
    except requests.exceptions.RequestException:
        echo(
            style(
                "\nCould not establish a connection to EvalAI."
                " Please check the Host URL.\n",
                bold=True,
                fg="red",
            ))
        sys.exit(1)

    response = response.json()
    challenges = response["results"]

    # Filter out past/unapproved/unpublished challenges.
    challenges = list(
        filter(
            lambda challenge: validate_date_format(challenge["end_date"]) >
            datetime.now() and challenge["approved_by_admin"] and challenge[
                "published"],
            challenges,
        ))

    if len(challenges) != 0:
        pretty_print_challenge_data(challenges)
    else:
        echo(style(
            "Sorry, no challenges found.",
            fg="red",
            bold=True,
        ))
Пример #11
0
def display_leaderboard(challenge_id, phase_split_id):
    """
    Function to display the Leaderboard of a particular CPS.
    """
    url = "{}{}".format(get_host_url(), URLS.leaderboard.value)
    url = url.format(phase_split_id)
    headers = get_request_header()
    try:
        response = requests.get(url, headers=headers)
        response.raise_for_status()
    except requests.exceptions.HTTPError as err:
        if response.status_code in EVALAI_ERROR_CODES:
            validate_token(response.json())
            echo(
                style(
                    "Error: {}".format(response.json()["error"]),
                    fg="red",
                    bold=True,
                ))
        else:
            echo(style(err, fg="red", bold=True))
        sys.exit(1)
    except requests.exceptions.RequestException:
        echo(
            style(
                "\nCould not establish a connection to EvalAI."
                " Please check the Host URL.\n",
                bold=True,
                fg="red",
            ))
        sys.exit(1)

    response = response.json()

    results = response["results"]
    if len(results) != 0:
        attributes = results[0]["leaderboard__schema"]["labels"]
        pretty_print_leaderboard_data(attributes, results)
    else:
        echo(
            "Sorry, no Leaderboard results found.",
            bold=True,
            fg="red",
        )
Пример #12
0
def display_challenge_phase_split_list(challenge_id):
    """
    Function to display Challenge Phase Splits of a particular challenge.
    """
    url = URLS.challenge_phase_split_detail.value
    url = "{}{}".format(get_host_url(), url)
    url = url.format(challenge_id)
    headers = get_request_header()
    try:
        response = requests.get(url, headers=headers)
        response.raise_for_status()
    except requests.exceptions.HTTPError as err:
        if response.status_code in EVALAI_ERROR_CODES:
            validate_token(response.json())
            echo(
                style(
                    "\nError: {}\n"
                    "\nUse `evalai challenges` to fetch the active challenges.\n"
                    "\nUse `evalai challenge CHALLENGE phases` to fetch the "
                    "active phases.\n".format(response.json()["error"]),
                    fg="red",
                    bold=True,
                ))
        else:
            echo(style(err, fg="red", bold=True))
        sys.exit(1)
    except requests.exceptions.RequestException:
        echo(
            style(
                "\nCould not establish a connection to EvalAI."
                " Please check the Host URL.\n",
                bold=True,
                fg="red",
            ))
        sys.exit(1)

    phase_splits = response.json()
    if len(phase_splits) != 0:
        pretty_print_challenge_phase_split_data(phase_splits)
    else:
        echo(
            style("Sorry, no Challenge Phase Splits found.",
                  fg="red",
                  bold=True))
Пример #13
0
def display_my_submission_details(challenge_id, phase_id, start_date, end_date):
    """
    Function to display the details of a particular submission.
    """
    url = URLS.my_submissions.value
    url = "{}{}".format(get_host_url(), url)
    url = url.format(challenge_id, phase_id)
    headers = get_request_header()

    try:
        response = requests.get(url, headers=headers)
        response.raise_for_status()
    except requests.exceptions.HTTPError as err:
        if response.status_code in EVALAI_ERROR_CODES:
            validate_token(response.json())
            echo(
                style(
                    "\nError: {}\n"
                    "\nUse `evalai challenges` to fetch the active challenges.\n"
                    "\nUse `evalai challenge CHALLENGE phases` to fetch the "
                    "active phases.\n".format(response.json()["error"]),
                    fg="red",
                    bold=True,
                )
            )
        else:
            echo(err)
        sys.exit(1)
    except requests.exceptions.RequestException as err:
        echo(
            style(
                "\nCould not establish a connection to EvalAI."
                " Please check the Host URL.\n",
                bold=True,
                fg="red",
            )
        )
        sys.exit(1)

    response = response.json()

    submissions = response["results"]
    pretty_print_my_submissions_data(submissions, start_date, end_date)
Пример #14
0
def display_challenge_details(challenge):
    """
    Function to display challenge details.
    """
    url = URLS.challenge_details.value
    url = "{}{}".format(get_host_url(), url)
    url = url.format(challenge)

    header = get_request_header()
    try:
        response = requests.get(url, headers=header)
        response.raise_for_status()
    except requests.exceptions.HTTPError as err:
        if response.status_code in EVALAI_ERROR_CODES:
            validate_token(response.json())
            echo(
                style(
                    "\nError: {}".format(response.json()["error"]),
                    fg="red",
                    bold=True,
                ))
            echo(
                style(
                    "\nUse `evalai challenges` to fetch the active challenges.\n",
                    fg="red",
                    bold=True,
                ))
        else:
            echo(style(err, fg="red", bold=True))
        sys.exit(1)
    except requests.exceptions.RequestException:
        echo(
            style(
                "\nCould not establish a connection to EvalAI."
                " Please check the Host URL.\n",
                bold=True,
                fg="red",
            ))
        sys.exit(1)

    response = response.json()
    pretty_print_challenge_details(response)
Пример #15
0
def display_teams(is_host):
    """
    Function to display all the participant or host teams of a user
    """
    url = "{}{}"
    headers = get_request_header()
    if is_host:
        url = url.format(get_host_url(), URLS.host_team_list.value)
    else:
        url = url.format(get_host_url(), URLS.participant_team_list.value)

    try:
        response = requests.get(url, headers=headers)
        response.raise_for_status()
    except requests.exceptions.HTTPError as err:
        if response.status_code in EVALAI_ERROR_CODES:
            validate_token(response.json())
            echo(
                style(
                    "Error: {}".format(response.json()["error"]),
                    fg="red",
                    bold=True,
                ))
        else:
            echo(err)
        sys.exit(1)
    except requests.exceptions.RequestException:
        echo(
            style(
                "\nCould not establish a connection to EvalAI."
                " Please check the Host URL.\n",
                bold=True,
                fg="red",
            ))
        sys.exit(1)
    response = response.json()

    teams = response["results"]
    if len(teams) != 0:
        pretty_print_team_data(teams, is_host)
    else:
        echo("Sorry, no teams found.")
Пример #16
0
    def setup(self):
        url = "{}{}"

        self.challenge_id = "2"
        self.team_id = "3"
        self.team_name = "TeamTest"
        self.expected_partic_team = "\nYour participant team {} was successfully created.\n".format(
            self.team_name)
        self.expected_host_team = "\nYour host team {} was successfully created.\n".format(
            self.team_name)
        self.expected_participate = "Your team id {} is now participating in this challenge.\n".format(
            self.team_id)

        headers = get_request_header()
        headers["Content-Type"] = "application/json"

        data = {}
        data["team_name"] = self.team_name
        data = json.loads(json.dumps(data))

        responses.add(responses.POST,
                      url.format(API_HOST_URL,
                                 URLS.participant_team_list.value),
                      headers=headers,
                      json=data,
                      status=201)

        responses.add(responses.POST,
                      url.format(API_HOST_URL, URLS.create_host_team.value),
                      headers=headers,
                      json=data,
                      status=201)

        responses.add(responses.POST,
                      url.format(API_HOST_URL,
                                 URLS.participate_in_a_challenge.value).format(
                                     self.challenge_id, self.team_id),
                      status=201)
Пример #17
0
def download_file(url):
    """
    Download the file using URL with bucket and key
    """
    """
    Invoked by `evalai download_file URL`.
    """
    parsed_url = urlparse.urlparse(url)
    parsed_host_url = "{parsed_url.scheme}://{parsed_url.netloc}".format(
        parsed_url=parsed_url)
    is_correct_host = False
    curr_host = get_host_url()
    if parsed_host_url in EVALAI_API_URLS:
        if parsed_host_url == curr_host:
            is_correct_host = True

    if is_correct_host:
        bucket = urlparse.parse_qs(parsed_url.query).get("bucket")
        key = urlparse.parse_qs(parsed_url.query).get("key")
        if not bucket or not key:
            echo(
                style(
                    "\nThe bucket or key is missing in the url.\n",
                    fg="red",
                    bold=True,
                ))
            sys.exit(1)

        headers = get_request_header()
        file_name = key[0].split("/")[-1]
        URL = URLS.download_file.value
        URL = "{}{}".format(get_host_url(), URL)
        URL = URL.format(bucket[0], key[0])
        try:
            response = requests.get(URL, headers=headers)
            response.raise_for_status()
        except requests.exceptions.HTTPError as err:
            if response.status_code in EVALAI_ERROR_CODES:
                validate_token(response.json())
                echo(
                    style(
                        "\nError: {}\n".format(response.json()["error"]),
                        fg="red",
                        bold=True,
                    ))
            else:
                echo(err)
            sys.exit(1)
        except requests.exceptions.RequestException as e:
            echo(
                style(
                    "\nCould not connect to EvalAI API. Please check"
                    " the URL or if server is running\n",
                    bold=True,
                    fg="red",
                ))
            sys.exit(1)
        with open(file_name, "wb") as file:
            total_file_length = int(response.headers.get("content-length"))
            chunk_size = 1024
            with click.progressbar(length=total_file_length,
                                   label="Downloading file") as bar:
                for data in response.iter_content(chunk_size=chunk_size):
                    file.write(data)
                    bar.update(chunk_size)
            echo(
                style(
                    "\nYour file {} is successfully downloaded.\n".format(
                        file_name),
                    fg="green",
                    bold=True,
                ))
    else:
        echo(
            style(
                "\nThe url doesn't match the EvalAI url. Please check the url.\n",
                fg="red",
                bold=True,
            ))
        sys.exit(1)
Пример #18
0
def upload_file_using_presigned_url(challenge_phase_pk,
                                    file,
                                    file_type,
                                    submission_metadata={}):
    if file_type == "submission":
        url = "{}{}".format(get_host_url(),
                            URLS.get_presigned_url_for_submission_file.value)
    elif file_type == "annotation":
        url = "{}{}".format(get_host_url(),
                            URLS.get_presigned_url_for_annotation_file.value)
    url = url.format(challenge_phase_pk)
    headers = get_request_header()

    try:
        # Fetching the presigned url
        if file_type == "submission":
            data = {"status": "submitting", "file_name": file.name}
            data = dict(data, **submission_metadata)
            response = requests.post(url, headers=headers, data=data)
            if response.status_code is not HTTPStatus.CREATED:
                response.raise_for_status()
        elif file_type == "annotation":
            data = {"file_name": file.name}
            response = requests.get(url, headers=headers, data=data)
            if response.status_code is not HTTPStatus.OK:
                response.raise_for_status()

        response = response.json()
        presigned_url = response.get("presigned_url")
        if file_type == "submission":
            submission_pk = response.get("submission_pk")

        # Uploading the file to S3
        response = upload_file_to_s3(file, presigned_url)
        if response.status_code is not HTTPStatus.OK:
            response.raise_for_status()

        if file_type == "submission":
            # Publishing submission message to the message queue for processing
            url = "{}{}".format(get_host_url(),
                                URLS.send_submission_message.value)
            url = url.format(challenge_phase_pk, submission_pk)
            response = requests.post(
                url,
                headers=headers,
            )
            response.raise_for_status()
    except requests.exceptions.HTTPError as err:
        if response.status_code in EVALAI_ERROR_CODES:
            validate_token(response.json())
            if file_type == "submission":
                error_message = "\nThere was an error while making the submission: {}\n".format(
                    response.json()["error"])
            elif file_type == "annotation":
                error_message = "\nThere was an error while uploading the annotation file: {}".format(
                    response.json()["error"])
            echo(style(
                error_message,
                fg="red",
                bold=True,
            ))
        else:
            echo(style("{}".format(err), fg='red'))
        sys.exit(1)
    except requests.exceptions.RequestException:
        echo(
            style(
                "\nCould not establish a connection to EvalAI."
                " Please check the Host URL.\n",
                bold=True,
                fg="red",
            ))
        sys.exit(1)

    if file_type == "submission":
        success_message = "\nYour submission {} with the id {} is successfully submitted for evaluation.\n".format(
            file.name, submission_pk)
    elif file_type == "annotation":
        success_message = "\nThe annotation file {} for challenge phase {} is successfully uploaded.\n".format(
            file.name, challenge_phase_pk)
    echo(style(
        success_message,
        fg="green",
        bold=True,
    ))
Пример #19
0
def create_team(team_name, team_url, is_host):
    """
    Function to create a new team by taking in the team name as input.
    """
    url = "{}{}"

    if is_host:
        url = url.format(get_host_url(), URLS.create_host_team.value)
    else:
        url = url.format(get_host_url(), URLS.participant_team_list.value)

    headers = get_request_header()
    headers["Content-Type"] = "application/json"

    data = {}
    data["team_name"] = team_name
    if team_url:
        data["team_url"] = team_url
    data = json.dumps(data)
    try:
        response = requests.post(url, headers=headers, data=data)
        response.raise_for_status()
    except requests.exceptions.HTTPError as err:
        if response.status_code in EVALAI_ERROR_CODES:
            validate_token(response.json())
            if "team_name" in response.json().keys():
                validate_token(response.json())
                echo(
                    style(
                        "Error: {}".format(response.json()["team_name"][0]),
                        fg="red",
                        bold=True,
                    ))
            else:
                echo(
                    style(
                        "Error: {}".format(response.json()["error"]),
                        fg="red",
                        bold=True,
                    ))
        else:
            echo(err)
        sys.exit(1)
    except requests.exceptions.RequestException:
        echo(
            style(
                "\nCould not establish a connection to EvalAI."
                " Please check the Host URL.\n",
                bold=True,
                fg="red",
            ))
        sys.exit(1)

    if response.status_code == 201:
        response = response.json()
        if is_host:
            echo(
                style(
                    "\nYour host team {} was successfully created.\n".format(
                        response["team_name"]),
                    fg="green",
                    bold=True,
                ))
        else:
            echo(
                style(
                    "\nYour participant team {} was successfully created.\n".
                    format(response["team_name"]),
                    fg="green",
                    bold=True,
                ))
Пример #20
0
def upload_file_using_presigned_url(challenge_phase_pk, file, file_type, submission_metadata={}):
    if file_type == "submission":
        url = "{}{}".format(get_host_url(), URLS.get_presigned_url_for_submission_file.value)
        finish_upload_url = "{}{}".format(get_host_url(), URLS.finish_upload_for_submission_file.value)
    elif file_type == "annotation":
        url = "{}{}".format(get_host_url(), URLS.get_presigned_url_for_annotation_file.value)
        finish_upload_url = "{}{}".format(get_host_url(), URLS.finish_upload_for_annotation_file.value)
    url = url.format(challenge_phase_pk)
    headers = get_request_header()

    # Limit to max 100 MB chunk for multipart upload
    max_chunk_size = 100 * 1024 * 1024

    try:
        # Fetching the presigned url
        if file_type == "submission":
            file_size = Path(file.name).stat().st_size
            num_file_chunks = int(file_size / max_chunk_size) + 1
            data = {"status": "submitting", "file_name": file.name, "num_file_chunks": num_file_chunks}
            data = dict(data, **submission_metadata)
            response = requests.post(
                url, headers=headers, data=data
            )

            if response.status_code is not HTTPStatus.CREATED:
                response.raise_for_status()

            # Update url params for multipart upload on S3
            finish_upload_url = finish_upload_url.format(challenge_phase_pk, response.json().get("submission_pk"))
        elif file_type == "annotation":
            file_size = Path(file.name).stat().st_size
            num_file_chunks = int(file_size / max_chunk_size) + 1

            data = {"file_name": file.name, "num_file_chunks": num_file_chunks}
            response = requests.post(url, headers=headers, data=data)
            if response.status_code is not HTTPStatus.OK:
                response.raise_for_status()

            # Update url params for multipart upload on S3
            finish_upload_url = finish_upload_url.format(challenge_phase_pk)

        response = response.json()
        presigned_urls = response.get("presigned_urls")
        upload_id = response.get("upload_id")
        if file_type == "submission":
            submission_pk = response.get("submission_pk")

        # Uploading the file to S3
        response = upload_file_to_s3(file, presigned_urls, max_chunk_size)

        data = {
            "parts": json.dumps(response.get("parts")),
            "upload_id": upload_id
        }

        # Complete multipart S3 upload
        response = requests.post(
            finish_upload_url, headers=headers, data=data
        )

        if response.status_code is not HTTPStatus.OK:
            response.raise_for_status()

        if file_type == "submission":
            # Publishing submission message to the message queue for processing
            url = "{}{}".format(get_host_url(), URLS.send_submission_message.value)
            url = url.format(challenge_phase_pk, submission_pk)
            response = requests.post(
                url,
                headers=headers,
            )
            response.raise_for_status()
    except requests.exceptions.HTTPError as err:
        if response.status_code in EVALAI_ERROR_CODES:
            validate_token(response.json())
            if file_type == "submission":
                error_message = "\nThere was an error while making the submission: {}\n".format(response.json()["error"])
            elif file_type == "annotation":
                error_message = "\nThere was an error while uploading the annotation file: {}".format(response.json()["error"])
            echo(
                style(
                    error_message,
                    fg="red",
                    bold=True,
                )
            )
        else:
            echo(style("{}".format(err), fg='red'))
        sys.exit(1)
    except requests.exceptions.RequestException:
        echo(
            style(
                "\nCould not establish a connection to EvalAI."
                " Please check the Host URL.\n",
                bold=True,
                fg="red",
            )
        )
        sys.exit(1)

    if file_type == "submission":
        success_message = "\nYour submission {} with the id {} is successfully submitted for evaluation.\n".format(
            file.name, submission_pk
        )
    elif file_type == "annotation":
        success_message = "\nThe annotation file {} for challenge phase {} is successfully uploaded.\n".format(
            file.name, challenge_phase_pk
        )
    echo(
        style(
            success_message,
            fg="green",
            bold=True,
        )
    )