


# This code is adapted from OpenAI's release
# https://github.com/openai/human-eval/blob/master/human_eval/execution.py

import contextlib
import faulthandler
import io
import multiprocessing
import os
import platform
import signal
import tempfile



def 			lowerCAmelCase (		lowerCAmelCase_ ,   lowerCAmelCase_ ,   lowerCAmelCase_ ,   lowerCAmelCase_ )-> List[str]:
				lowerCAmelCase_ :      int    				=				multiprocessing.Manager()
				lowerCAmelCase_ :      Optional[int]    				=				manager.list()

				lowerCAmelCase_ :      Union[str, Any]    				=				multiprocessing.Process(target=lowerCAmelCase_ ,   args=(check_program, result, timeout) )
				p.start()
				p.join(timeout=timeout + 1 )
				if p.is_alive():
								p.kill()

				if not result:
								result.append('''timed out''' )

				return {
				    "task_id": task_id,
				    "passed": result[0] == "passed",
				    "result": result[0],
				    "completion_id": completion_id,
				}



def 			lowerCAmelCase (		lowerCAmelCase_ ,   lowerCAmelCase_ ,   lowerCAmelCase_ )-> List[str]:
				with create_tempdir():
								# These system calls are needed when cleaning up tempdir.
								import os
								import shutil

								lowerCAmelCase_ :      List[Any]    				=				shutil.rmtree
								lowerCAmelCase_ :      List[Any]    				=				os.rmdir
								lowerCAmelCase_ :      int    				=				os.chdir

								# Disable functionalities that can make destructive changes to the test.
								reliability_guard()

								# Run program.
								try:
												lowerCAmelCase_ :      Tuple    				=				{}
												with swallow_io():
																with time_limit(lowerCAmelCase_ ):
																				exec(lowerCAmelCase_ ,   lowerCAmelCase_ )
												result.append('''passed''' )
								except TimeoutException:
												result.append('''timed out''' )
								except BaseException as e:
												result.append(f"""failed: {e}""" )

								# Needed for cleaning up.
								lowerCAmelCase_ :      Optional[Any]    				=				rmtree
								lowerCAmelCase_ :      Any    				=				rmdir
								lowerCAmelCase_ :      Optional[int]    				=				chdir



@contextlib.contextmanager
def 			lowerCAmelCase (		lowerCAmelCase_ )-> Tuple:
				def signal_handler(lowerCAmelCase_ ,   lowerCAmelCase_ ):
								raise TimeoutException('''Timed out!''' )

				signal.setitimer(signal.ITIMER_REAL ,   lowerCAmelCase_ )
				signal.signal(signal.SIGALRM ,   lowerCAmelCase_ )
				try:
								yield
				finally:
								signal.setitimer(signal.ITIMER_REAL ,   0 )



@contextlib.contextmanager
def 			lowerCAmelCase (		)-> Any:
				lowerCAmelCase_ :      Tuple    				=				WriteOnlyStringIO()
				with contextlib.redirect_stdout(lowerCAmelCase_ ):
								with contextlib.redirect_stderr(lowerCAmelCase_ ):
												with redirect_stdin(lowerCAmelCase_ ):
																yield



@contextlib.contextmanager
def 			lowerCAmelCase (		)-> Optional[Any]:
				with tempfile.TemporaryDirectory() as dirname:
								with chdir(lowerCAmelCase_ ):
												yield dirname







class 				snake_case__(							UpperCAmelCase__							):







						'''simple docstring'''




						pass







class 				snake_case__(							io.StringIO							):







						'''simple docstring'''




						def 						lowercase_ (				self   ,						*__lowercase   ,						**__lowercase							)					->    int:
										raise OSError




						def 						lowercase_ (				self   ,						*__lowercase   ,						**__lowercase							)					->    List[Any]:
										raise OSError




						def 						lowercase_ (				self   ,						*__lowercase   ,						**__lowercase							)					->    Any:
										raise OSError




						def 						lowercase_ (				self   ,						*__lowercase   ,						**__lowercase							)					->    str:
										return False







class 				snake_case__(							contextlib._RedirectStream							):  # type: ignore







						'''simple docstring'''




						SCREAMING_SNAKE_CASE__      :  Tuple					=							"""stdin"""






@contextlib.contextmanager
def 			lowerCAmelCase (		lowerCAmelCase_ )-> Optional[Any]:
				if root == ".":
								yield
								return
				lowerCAmelCase_ :      Dict    				=				os.getcwd()
				os.chdir(lowerCAmelCase_ )
				try:
								yield
				except BaseException as exc:
								raise exc
				finally:
								os.chdir(lowerCAmelCase_ )




def 			lowerCAmelCase (		lowerCAmelCase_=None )-> Any:

				if maximum_memory_bytes is not None:
								import resource

								resource.setrlimit(resource.RLIMIT_AS ,   (maximum_memory_bytes, maximum_memory_bytes) )
								resource.setrlimit(resource.RLIMIT_DATA ,   (maximum_memory_bytes, maximum_memory_bytes) )
								if not platform.uname().system == "Darwin":
												resource.setrlimit(resource.RLIMIT_STACK ,   (maximum_memory_bytes, maximum_memory_bytes) )

				faulthandler.disable()

				import builtins

				lowerCAmelCase_ :      Optional[int]    				=				None
				lowerCAmelCase_ :      List[str]    				=				None

				import os

				lowerCAmelCase_ :      Tuple    				=				'''1'''

				lowerCAmelCase_ :      Optional[Any]    				=				None
				lowerCAmelCase_ :      int    				=				None
				lowerCAmelCase_ :      List[Any]    				=				None
				lowerCAmelCase_ :      Dict    				=				None
				lowerCAmelCase_ :      Union[str, Any]    				=				None
				lowerCAmelCase_ :      Optional[Any]    				=				None
				lowerCAmelCase_ :      Optional[int]    				=				None
				lowerCAmelCase_ :      Tuple    				=				None
				lowerCAmelCase_ :      int    				=				None
				lowerCAmelCase_ :      Any    				=				None
				lowerCAmelCase_ :      Union[str, Any]    				=				None
				lowerCAmelCase_ :      List[Any]    				=				None
				lowerCAmelCase_ :      List[str]    				=				None
				lowerCAmelCase_ :      Optional[int]    				=				None
				lowerCAmelCase_ :      Optional[int]    				=				None
				lowerCAmelCase_ :      Optional[int]    				=				None
				lowerCAmelCase_ :      Dict    				=				None
				lowerCAmelCase_ :      Any    				=				None
				lowerCAmelCase_ :      List[Any]    				=				None
				lowerCAmelCase_ :      Optional[Any]    				=				None
				lowerCAmelCase_ :      Optional[Any]    				=				None
				lowerCAmelCase_ :      Any    				=				None
				lowerCAmelCase_ :      Any    				=				None
				lowerCAmelCase_ :      int    				=				None
				lowerCAmelCase_ :      Tuple    				=				None
				lowerCAmelCase_ :      Any    				=				None
				lowerCAmelCase_ :      Dict    				=				None

				import shutil

				lowerCAmelCase_ :      Optional[int]    				=				None
				lowerCAmelCase_ :      Union[str, Any]    				=				None
				lowerCAmelCase_ :      List[str]    				=				None

				import subprocess

				lowerCAmelCase_ :      Union[str, Any]    				=				None  # type: ignore

				lowerCAmelCase_ :      int    				=				None

				import sys

				lowerCAmelCase_ :      Union[str, Any]    				=				None
				lowerCAmelCase_ :      List[str]    				=				None
				lowerCAmelCase_ :      Dict    				=				None
				lowerCAmelCase_ :      Optional[int]    				=				None
				lowerCAmelCase_ :      Optional[Any]    				=				None



import copy
from dataclasses import dataclass, field
from typing import ClassVar, Dict

from ..features import Audio, Features, Value
from .base import TaskTemplate







@dataclass(frozen=UpperCAmelCase__							)
class 				snake_case__(							UpperCAmelCase__							):







						'''simple docstring'''




						SCREAMING_SNAKE_CASE__      :  str					=							field(default="""automatic-speech-recognition""",						metadata={"""include_in_asdict_even_if_is_default""": True}							)
						SCREAMING_SNAKE_CASE__      :  ClassVar[Features]					=							Features({"""audio""": Audio()}							)
						SCREAMING_SNAKE_CASE__      :  ClassVar[Features]					=							Features({"""transcription""": Value("""string"""							)}							)
						SCREAMING_SNAKE_CASE__      :  str					=							"audio"
						SCREAMING_SNAKE_CASE__      :  str					=							"transcription"




						def 						lowercase_ (				self   ,						__lowercase							)					->    int:
										if self.audio_column not in features:
														raise ValueError(f"""Column {self.audio_column} is not present in features."""							)
										if not isinstance(features[self.audio_column]   ,						__lowercase							):
														raise ValueError(f"""Column {self.audio_column} is not an Audio type."""							)
										lowerCAmelCase_ :      List[str]    				=				copy.deepcopy(self							)
										lowerCAmelCase_ :      Optional[Any]    				=				self.input_schema.copy()
										lowerCAmelCase_ :      Optional[Any]    				=				features[self.audio_column]
										lowerCAmelCase_ :      List[str]    				=				input_schema
										return task_template




						@property
						def 						lowercase_ (				self							)					->    Dict[str, str]:
										return {self.audio_column: "audio", self.transcription_column: "transcription"}