"""simple docstring"""






from copy import deepcopy
from unittest.case import TestCase

import pytest

from datasets.arrow_dataset import Dataset
from datasets.features import Audio, ClassLabel, Features, Image, Sequence, Value
from datasets.info import DatasetInfo
from datasets.tasks import (
    AudioClassification,
    AutomaticSpeechRecognition,
    ImageClassification,
    LanguageModeling,
    QuestionAnsweringExtractive,
    Summarization,
    TextClassification,
    task_template_from_dict,
)
from datasets.utils.py_utils import asdict


lowerCAmelCase__    :    str			=      {
    'id': '5733be284776f41900661182',
    'title': 'University_of_Notre_Dame',
    'context': 'Architecturally, the school has a Catholic character. Atop the Main Building\'s gold dome is a golden statue of the Virgin Mary. Immediately in front of the Main Building and facing it, is a copper statue of Christ with arms upraised with the legend "Venite Ad Me Omnes". Next to the Main Building is the Basilica of the Sacred Heart. Immediately behind the basilica is the Grotto, a Marian place of prayer and reflection. It is a replica of the grotto at Lourdes, France where the Virgin Mary reputedly appeared to Saint Bernadette Soubirous in 1858. At the end of the main drive (and in a direct line that connects through 3 statues and the Gold Dome), is a simple, modern stone statue of Mary.',
    'question': 'To whom did the Virgin Mary allegedly appear in 1858 in Lourdes France?',
    'answers': {'text': ['Saint Bernadette Soubirous'], 'answer_start': [515]},
}



@pytest.mark.parametrize(
    'task_cls'   ,     [
        AudioClassification,
        AutomaticSpeechRecognition,
        ImageClassification,
        LanguageModeling,
        QuestionAnsweringExtractive,
        Summarization,
        TextClassification,
    ]   ,     )
def     a_		(   lowerCamelCase			):
				UpperCAmelCase__			 =				task_cls()
				UpperCAmelCase__			 =				asdict(lowerCamelCase			)
				UpperCAmelCase__			 =				task_template_from_dict(lowerCamelCase			)
				assert task == reloaded
class 							snake_case			:




					"""simple docstring"""

					def 						__lowerCAmelCase		(							self  :      Any     ):
									UpperCAmelCase__			 =				LanguageModeling(text_column='input_text'     )
									assert {"input_text": "text"} == task.column_mapping







					def 						__lowerCAmelCase		(							self  :      Dict     ):
									UpperCAmelCase__			 =				Features({'text': Value('string'     )}     )
									UpperCAmelCase__			 =				{'text_column': 'input_text'}
									UpperCAmelCase__			 =				LanguageModeling.from_dict(lowerCamelCase__     )
									assert "language-modeling" == task.task
									assert input_schema == task.input_schema






class 							snake_case			(					__UpperCAmelCase							):




					"""simple docstring"""

					def 						__lowerCAmelCase		(							self  :      Union[str, Any]     ):
									UpperCAmelCase__			 =				sorted(['pos', 'neg']     )







					def 						__lowerCAmelCase		(							self  :      Dict     ):
									UpperCAmelCase__			 =				TextClassification(text_column='input_text'       ,label_column='input_label'     )
									self.assertDictEqual({'input_text': 'text', 'input_label': 'labels'}       ,task.column_mapping     )







					def 						__lowerCAmelCase		(							self  :      List[Any]     ):
									UpperCAmelCase__			 =				Features({'text': Value('string'     )}     )
									# Labels are cast to tuple during `TextClassification.__post_init__`, so we do the same here
									UpperCAmelCase__			 =				Features({'labels': ClassLabel}     )
									UpperCAmelCase__			 =				{'text_column': 'input_text', 'label_column': 'input_labels'}
									UpperCAmelCase__			 =				TextClassification.from_dict(lowerCamelCase__     )
									self.assertEqual('text-classification'       ,task.task     )
									self.assertEqual(lowerCamelCase__       ,task.input_schema     )
									self.assertEqual(lowerCamelCase__       ,task.label_schema     )







					def 						__lowerCAmelCase		(							self  :      List[str]     ):
									UpperCAmelCase__			 =				TextClassification(text_column='input_text'       ,label_column='input_label'     )
									self.assertEqual(task.label_schema['labels']       ,lowerCamelCase__     )
									UpperCAmelCase__			 =				task.align_with_features(Features({'input_label': ClassLabel(names=self.labels     )}     )     )
									self.assertEqual(task.label_schema['labels']       ,ClassLabel(names=self.labels     )     )






class 							snake_case			(					__UpperCAmelCase							):




					"""simple docstring"""

					def 						__lowerCAmelCase		(							self  :      Optional[Any]     ):
									UpperCAmelCase__			 =				QuestionAnsweringExtractive(
									    context_column='input_context'       ,question_column='input_question'       ,answers_column='input_answers'     )
									self.assertDictEqual(
									    {'input_context': 'context', 'input_question': 'question', 'input_answers': 'answers'}       ,task.column_mapping     )







					def 						__lowerCAmelCase		(							self  :      Dict     ):
									UpperCAmelCase__			 =				Features({'question': Value('string'     ), 'context': Value('string'     )}     )
									UpperCAmelCase__			 =				Features(
									    {
									        'answers': Sequence(
									            {
									                'text': Value('string'     ),
									                'answer_start': Value('int32'     ),
									            }     )
									    }     )
									UpperCAmelCase__			 =				{
									    'context_column': 'input_input_context',
									    'question_column': 'input_question',
									    'answers_column': 'input_answers',
									}
									UpperCAmelCase__			 =				QuestionAnsweringExtractive.from_dict(lowerCamelCase__     )
									self.assertEqual('question-answering-extractive'       ,task.task     )
									self.assertEqual(lowerCamelCase__       ,task.input_schema     )
									self.assertEqual(lowerCamelCase__       ,task.label_schema     )






class 							snake_case			(					__UpperCAmelCase							):




					"""simple docstring"""

					def 						__lowerCAmelCase		(							self  :      List[Any]     ):
									UpperCAmelCase__			 =				Summarization(text_column='input_text'       ,summary_column='input_summary'     )
									self.assertDictEqual({'input_text': 'text', 'input_summary': 'summary'}       ,task.column_mapping     )







					def 						__lowerCAmelCase		(							self  :      Any     ):
									UpperCAmelCase__			 =				Features({'text': Value('string'     )}     )
									UpperCAmelCase__			 =				Features({'summary': Value('string'     )}     )
									UpperCAmelCase__			 =				{'text_column': 'input_text', 'summary_column': 'input_summary'}
									UpperCAmelCase__			 =				Summarization.from_dict(lowerCamelCase__     )
									self.assertEqual('summarization'       ,task.task     )
									self.assertEqual(lowerCamelCase__       ,task.input_schema     )
									self.assertEqual(lowerCamelCase__       ,task.label_schema     )






class 							snake_case			(					__UpperCAmelCase							):




					"""simple docstring"""

					def 						__lowerCAmelCase		(							self  :      Any     ):
									UpperCAmelCase__			 =				AutomaticSpeechRecognition(audio_column='input_audio'       ,transcription_column='input_transcription'     )
									self.assertDictEqual({'input_audio': 'audio', 'input_transcription': 'transcription'}       ,task.column_mapping     )







					def 						__lowerCAmelCase		(							self  :      int     ):
									UpperCAmelCase__			 =				Features({'audio': Audio()}     )
									UpperCAmelCase__			 =				Features({'transcription': Value('string'     )}     )
									UpperCAmelCase__			 =				{
									    'audio_column': 'input_audio',
									    'transcription_column': 'input_transcription',
									}
									UpperCAmelCase__			 =				AutomaticSpeechRecognition.from_dict(lowerCamelCase__     )
									self.assertEqual('automatic-speech-recognition'       ,task.task     )
									self.assertEqual(lowerCamelCase__       ,task.input_schema     )
									self.assertEqual(lowerCamelCase__       ,task.label_schema     )






class 							snake_case			(					__UpperCAmelCase							):




					"""simple docstring"""

					def 						__lowerCAmelCase		(							self  :      Optional[Any]     ):
									UpperCAmelCase__			 =				sorted(['pos', 'neg']     )







					def 						__lowerCAmelCase		(							self  :      Any     ):
									UpperCAmelCase__			 =				AudioClassification(audio_column='input_audio'       ,label_column='input_label'     )
									self.assertDictEqual({'input_audio': 'audio', 'input_label': 'labels'}       ,task.column_mapping     )







					def 						__lowerCAmelCase		(							self  :      int     ):
									UpperCAmelCase__			 =				Features({'audio': Audio()}     )
									UpperCAmelCase__			 =				Features({'labels': ClassLabel}     )
									UpperCAmelCase__			 =				{
									    'audio_column': 'input_image',
									    'label_column': 'input_label',
									}
									UpperCAmelCase__			 =				AudioClassification.from_dict(lowerCamelCase__     )
									self.assertEqual('audio-classification'       ,task.task     )
									self.assertEqual(lowerCamelCase__       ,task.input_schema     )
									self.assertEqual(lowerCamelCase__       ,task.label_schema     )







					def 						__lowerCAmelCase		(							self  :      Dict     ):
									UpperCAmelCase__			 =				AudioClassification(audio_column='input_audio'       ,label_column='input_label'     )
									self.assertEqual(task.label_schema['labels']       ,lowerCamelCase__     )
									UpperCAmelCase__			 =				task.align_with_features(Features({'input_label': ClassLabel(names=self.labels     )}     )     )
									self.assertEqual(task.label_schema['labels']       ,ClassLabel(names=self.labels     )     )






class 							snake_case			(					__UpperCAmelCase							):




					"""simple docstring"""

					def 						__lowerCAmelCase		(							self  :      str     ):
									UpperCAmelCase__			 =				sorted(['pos', 'neg']     )







					def 						__lowerCAmelCase		(							self  :      Dict     ):
									UpperCAmelCase__			 =				ImageClassification(image_column='input_image'       ,label_column='input_label'     )
									self.assertDictEqual({'input_image': 'image', 'input_label': 'labels'}       ,task.column_mapping     )







					def 						__lowerCAmelCase		(							self  :      Tuple     ):
									UpperCAmelCase__			 =				Features({'image': Image()}     )
									UpperCAmelCase__			 =				Features({'labels': ClassLabel}     )
									UpperCAmelCase__			 =				{
									    'image_column': 'input_image',
									    'label_column': 'input_label',
									}
									UpperCAmelCase__			 =				ImageClassification.from_dict(lowerCamelCase__     )
									self.assertEqual('image-classification'       ,task.task     )
									self.assertEqual(lowerCamelCase__       ,task.input_schema     )
									self.assertEqual(lowerCamelCase__       ,task.label_schema     )







					def 						__lowerCAmelCase		(							self  :      str     ):
									UpperCAmelCase__			 =				ImageClassification(image_column='input_image'       ,label_column='input_label'     )
									self.assertEqual(task.label_schema['labels']       ,lowerCamelCase__     )
									UpperCAmelCase__			 =				task.align_with_features(Features({'input_label': ClassLabel(names=self.labels     )}     )     )
									self.assertEqual(task.label_schema['labels']       ,ClassLabel(names=self.labels     )     )






class 							snake_case			(					__UpperCAmelCase							):




					"""simple docstring"""

					def 						__lowerCAmelCase		(							self  :      Union[str, Any]     ):
									UpperCAmelCase__			 =				DatasetInfo(task_templates=QuestionAnsweringExtractive()     )
									UpperCAmelCase__			 =				Dataset.from_dict({k: [v] for k, v in SAMPLE_QUESTION_ANSWERING_EXTRACTIVE.items()}       ,info=lowerCamelCase__     )
									assert isinstance(dataset.info.task_templates       ,lowerCamelCase__     )
									assert len(dataset.info.task_templates     ) == 1

									def keep_task(lowerCamelCase__  :      Dict     ):
													return x

									def dont_keep_task(lowerCamelCase__  :      List[str]     ):
													UpperCAmelCase__			 =				deepcopy(lowerCamelCase__     )
													UpperCAmelCase__			 =				0
													return out

									UpperCAmelCase__			 =				dataset.map(lowerCamelCase__     )
									assert mapped_dataset.info.task_templates == dataset.info.task_templates
									# reload from cache
									UpperCAmelCase__			 =				dataset.map(lowerCamelCase__     )
									assert mapped_dataset.info.task_templates == dataset.info.task_templates

									UpperCAmelCase__			 =				dataset.map(lowerCamelCase__     )
									assert mapped_dataset.info.task_templates == []
									# reload from cache
									UpperCAmelCase__			 =				dataset.map(lowerCamelCase__     )
									assert mapped_dataset.info.task_templates == []







					def 						__lowerCAmelCase		(							self  :      List[str]     ):
									UpperCAmelCase__			 =				Features({'text': Value('string'     ), 'label': ClassLabel(names=('pos', 'neg')     )}     )
									UpperCAmelCase__			 =				TextClassification(text_column='text'       ,label_column='label'     )
									UpperCAmelCase__			 =				DatasetInfo(features=lowerCamelCase__       ,task_templates=lowerCamelCase__     )
									UpperCAmelCase__			 =				Dataset.from_dict({'text': ['A sentence.'], 'label': ['pos']}       ,info=lowerCamelCase__     )

									def process(lowerCamelCase__  :      Dict     ):
													return example

									UpperCAmelCase__			 =				dataset.remove_columns('label'     )
									UpperCAmelCase__			 =				modified_dataset.map(lowerCamelCase__     )
									assert mapped_dataset.info.task_templates == []




"""simple docstring"""






import requests

try:
						from django.contrib.auth import authenticate, login
						from django.shortcuts import redirect, render
except ImportError:
						lowerCAmelCase__    :    Union[str, Any]			=      print



def     a_		(   lowerCamelCase			):
				# Enter your recaptcha secret key here
				UpperCAmelCase__			 =				'secretKey'
				UpperCAmelCase__			 =				'https://www.google.com/recaptcha/api/siteverify'

				# when method is not POST, direct user to login page
				if request.method != "POST":
								return render(lowerCamelCase   ,     'login.html'			)

				# from the frontend, get username, password, and client_key
				UpperCAmelCase__			 =				request.POST.get('username'			)
				UpperCAmelCase__			 =				request.POST.get('password'			)
				UpperCAmelCase__			 =				request.POST.get('g-recaptcha-response'			)

				# post recaptcha response to Google's recaptcha api
				UpperCAmelCase__			 =				requests.post(lowerCamelCase   ,     data={'secret': secret_key, 'response': client_key}			)
				# if the recaptcha api verified our keys
				if response.json().get('success'   ,     lowerCamelCase			):
								# authenticate the user
								UpperCAmelCase__			 =				authenticate(lowerCamelCase   ,     username=lowerCamelCase   ,     password=lowerCamelCase			)
								if user_in_database:
												login(lowerCamelCase   ,     lowerCamelCase			)
												return redirect('/your-webpage'			)
				return render(lowerCamelCase   ,     'login.html'			)



