def display_participated_or_hosted_challenges(is_host=False, is_participant=False): """ Function to display the participated or hosted challenges by a user """ challenges = [] if is_host: team_url = "{}{}".format(get_host_url(), URLS.host_teams.value) challenge_url = "{}{}".format(get_host_url(), URLS.host_challenges.value) teams = get_participant_or_host_teams(team_url) challenges = get_participant_or_host_team_challenges( challenge_url, teams) echo(style("\nHosted Challenges\n", bold=True)) if len(challenges) != 0: pretty_print_challenge_data(challenges) else: echo("Sorry, no challenges found.") if is_participant: team_url = "{}{}".format(get_host_url(), URLS.participant_teams.value) challenge_url = "{}{}".format(get_host_url(), URLS.participant_challenges.value) teams = get_participant_or_host_teams(team_url) challenges = get_participant_or_host_team_challenges( challenge_url, teams) if len(challenges) != 0: # 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 challenges: echo(style("\nParticipated Challenges\n", bold=True)) pretty_print_challenge_data(challenges) else: echo("Sorry, no challenges found.") else: echo("Sorry, no challenges found.")
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
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"))
def publish_submission_message(challenge_phase_pk, submission_pk, headers): url = "{}{}".format(get_host_url(), URLS.send_submission_message.value) url = url.format(challenge_phase_pk, submission_pk) response = requests.post( url, headers=headers, ) return response
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.")
def test_participate_in_a_challenge(self): terms_and_conditions_page_url = "{}{}".format( get_host_url(), URLS.terms_and_conditions_page.value) terms_and_conditions_page_url = terms_and_conditions_page_url.format(2) output = ( "Please refer challenge terms and conditions here: {}" "\n\nBy agreeing to participate in the challenge, you are agreeing to terms and conditions." "\n\nDo you accept challenge terms and conditions? [y/N]: Y\n". format(terms_and_conditions_page_url) + "Your team id {} is now participating in this challenge.\n".format( "3")) runner = CliRunner() result = runner.invoke(challenge, ["2", "participate", "3"], input="Y") response = result.output assert response == output
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)
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, ))
def test_participate_in_a_challenge_success(self): terms_and_conditions_page_url = "{}{}".format( get_host_url(), URLS.terms_and_conditions_page.value) terms_and_conditions_page_url = terms_and_conditions_page_url.format( self.challenge_id) expected = ( "Please refer challenge terms and conditions here: {}" "\n\nBy agreeing to participate in the challenge, you are agreeing to terms and conditions." "\n\nDo you accept challenge terms and conditions? [y/N]: Y\n". format(terms_and_conditions_page_url) + self.expected_participate) runner = CliRunner() result = runner.invoke( challenge, [self.challenge_id, "participate", self.team_id], input="Y") response = result.output assert response == expected
def participate(ctx, team): """ Participate in a challenge. """ """ Invoked by running `evalai challenge CHALLENGE participate TEAM` """ terms_and_conditions_page_url = "{}{}".format(get_host_url(), URLS.terms_and_conditions_page.value) terms_and_conditions_page_url = terms_and_conditions_page_url.format(ctx.challenge_id) message = "Please refer challenge terms and conditions here: {}" \ "\n\nBy agreeing to participate in the challenge, you are agreeing to terms and conditions." \ "\n\nDo you accept challenge terms and conditions?".format(terms_and_conditions_page_url) if click.confirm(message): participate_in_a_challenge(ctx.challenge_id, team) else: message = "\nYou can't participate in the challenge without accepting terms and conditions" notify_user(message, color="red")
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"]
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)
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, ))
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", )
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))
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)
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)
def test_participate_in_a_challenge_for_http_error_404(self): terms_and_conditions_page_url = "{}{}".format( get_host_url(), URLS.terms_and_conditions_page.value) terms_and_conditions_page_url = terms_and_conditions_page_url.format(2) url = "{}{}".format(API_HOST_URL, URLS.participate_in_a_challenge.value).format( "2", "3") expected = ( "Please refer challenge terms and conditions here: {}" "\n\nBy agreeing to participate in the challenge, you are agreeing to terms and conditions." "\n\nDo you accept challenge terms and conditions? [y/N]: Y\n". format(terms_and_conditions_page_url) + self.expected.format(url) + "\n") runner = CliRunner() result = runner.invoke(challenge, ["2", "participate", "3"], input="Y") response = result.output assert response == expected
def test_participate_in_a_challenge_when_object_does_not_exist(self): terms_and_conditions_page_url = "{}{}".format( get_host_url(), URLS.terms_and_conditions_page.value) terms_and_conditions_page_url = terms_and_conditions_page_url.format(2) expected = ( "Please refer challenge terms and conditions here: {}" "\n\nBy agreeing to participate in the challenge, you are agreeing to terms and conditions." "\n\nDo you accept challenge terms and conditions? [y/N]: Y\n\n". format(terms_and_conditions_page_url) + self.expected) runner = CliRunner() result = runner.invoke(challenge, ["2", "participate", "3"], input="Y") response = result.output.rstrip() expected = "{}\n\n{}".format( expected, "Use `evalai challenges` to fetch the active challenges.", ) expected = "{}\n\n{}".format( expected, "Use `evalai teams` to fetch your participant teams.") assert response == expected
def display_past_challenge_list(): """ Displays the list of past challenges from the backend """ url = "{}{}".format(get_host_url(), URLS.past_challenge_list.value) display_challenges(url)
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, ) )
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)
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, ))
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, ))