






import os
from datetime import datetime as dt

from github import Github


UpperCamelCase								=		[
    "good first issue",
    "feature request",
    "wip",
]






def    __magic_name__    (	)     ->    List[str]:
							_lowercase							:   Union[str, Any] 							=   Github(os.environ['GITHUB_TOKEN']				)
							_lowercase							:   str 							=   g.get_repo('huggingface/accelerate'				)
							_lowercase							:   Any 							=   repo.get_issues(state='open'				)

							for issue in open_issues:
														_lowercase							:   Dict 							=   sorted([comment for comment in issue.get_comments()]     ,     key=lambda SCREAMING_SNAKE_CASE				: i.created_at     ,     reverse=SCREAMING_SNAKE_CASE				)
														_lowercase							:   Any 							=   comments[0] if len(SCREAMING_SNAKE_CASE				) > 0 else None
														_lowercase							:   Optional[Any] 							=   dt.utcnow()
														_lowercase							:   str 							=   (current_time - issue.updated_at).days
														_lowercase							:   Dict 							=   (current_time - issue.created_at).days
														if (
														    last_comment is not None
														    and last_comment.user.login == "github-actions[bot]"
														    and days_since_updated > 7
														    and days_since_creation >= 30
														    and not any(label.name.lower() in LABELS_TO_EXEMPT for label in issue.get_labels()				)
														):
																					# Close issue since it has been 7 days of inactivity since bot mention.
																					issue.edit(state='closed'				)
														elif (
														    days_since_updated > 23
														    and days_since_creation >= 30
														    and not any(label.name.lower() in LABELS_TO_EXEMPT for label in issue.get_labels()				)
														):
																					# Add stale comment
																					issue.create_comment(
																					    'This issue has been automatically marked as stale because it has not had '
																					    'recent activity. If you think this still needs to be addressed '
																					    'please comment on this thread.\n\nPlease note that issues that do not follow the '
																					    '[contributing guidelines](https://github.com/huggingface/accelerate/blob/main/CONTRIBUTING.md) '
																					    'are likely to be ignored.'				)


if __name__ == "__main__":
							main()












import shutil
import tempfile
import unittest

from transformers import ClapFeatureExtractor, ClapProcessor, RobertaTokenizer, RobertaTokenizerFast
from transformers.testing_utils import require_sentencepiece, require_torchaudio

from .test_feature_extraction_clap import floats_list



@require_torchaudio
@require_sentencepiece
class 				_UpperCamelCase      (unittest.TestCase      ):


      def 			__UpperCAmelCase		(						self						)->						Optional[int]:
           __lowerCAmelCase             =       "laion/clap-htsat-unfused"
           __lowerCAmelCase             =       tempfile.mkdtemp()


      def 			__UpperCAmelCase		(						self       ,    **__UpperCamelCase						)->						Optional[int]:
           return RobertaTokenizer.from_pretrained(self.checkpoint       ,    **__UpperCamelCase						)


      def 			__UpperCAmelCase		(						self       ,    **__UpperCamelCase						)->						List[Any]:
           return ClapFeatureExtractor.from_pretrained(self.checkpoint       ,    **__UpperCamelCase						)


      def 			__UpperCAmelCase		(						self						)->						Union[str, Any]:
           shutil.rmtree(self.tmpdirname						)


      def 			__UpperCAmelCase		(						self						)->						Dict:
           __lowerCAmelCase             =       self.get_tokenizer()
           __lowerCAmelCase             =       self.get_feature_extractor()

           __lowerCAmelCase             =       ClapProcessor(tokenizer=__UpperCamelCase       ,    feature_extractor=__UpperCamelCase						)

           processor.save_pretrained(self.tmpdirname						)
           __lowerCAmelCase             =       ClapProcessor.from_pretrained(self.tmpdirname						)

           self.assertEqual(processor.tokenizer.get_vocab()       ,    tokenizer.get_vocab()						)
           self.assertIsInstance(processor.tokenizer       ,    __UpperCamelCase						)

           self.assertEqual(processor.feature_extractor.to_json_string()       ,    feature_extractor.to_json_string()						)
           self.assertIsInstance(processor.feature_extractor       ,    __UpperCamelCase						)


      def 			__UpperCAmelCase		(						self						)->						List[str]:
           __lowerCAmelCase             =       ClapProcessor(tokenizer=self.get_tokenizer()       ,    feature_extractor=self.get_feature_extractor()						)
           processor.save_pretrained(self.tmpdirname						)

           __lowerCAmelCase             =       self.get_tokenizer(bos_token="(BOS)"       ,    eos_token="(EOS)"						)
           __lowerCAmelCase             =       self.get_feature_extractor(do_normalize=__UpperCamelCase       ,    padding_value=1.0						)

           __lowerCAmelCase             =       ClapProcessor.from_pretrained(
               self.tmpdirname       ,    bos_token="(BOS)"       ,    eos_token="(EOS)"       ,    do_normalize=__UpperCamelCase       ,    padding_value=1.0						)

           self.assertEqual(processor.tokenizer.get_vocab()       ,    tokenizer_add_kwargs.get_vocab()						)
           self.assertIsInstance(processor.tokenizer       ,    __UpperCamelCase						)

           self.assertEqual(processor.feature_extractor.to_json_string()       ,    feature_extractor_add_kwargs.to_json_string()						)
           self.assertIsInstance(processor.feature_extractor       ,    __UpperCamelCase						)


      def 			__UpperCAmelCase		(						self						)->						List[str]:
           __lowerCAmelCase             =       self.get_feature_extractor()
           __lowerCAmelCase             =       self.get_tokenizer()

           __lowerCAmelCase             =       ClapProcessor(tokenizer=__UpperCamelCase       ,    feature_extractor=__UpperCamelCase						)

           __lowerCAmelCase             =       floats_list((3, 1_0_0_0)						)

           __lowerCAmelCase             =       feature_extractor(__UpperCamelCase       ,    return_tensors="np"						)
           __lowerCAmelCase             =       processor(audios=__UpperCamelCase       ,    return_tensors="np"						)

           for key in input_feat_extract.keys():
                self.assertAlmostEqual(input_feat_extract[key].sum()       ,    input_processor[key].sum()       ,    delta=1e-2						)


      def 			__UpperCAmelCase		(						self						)->						Dict:
           __lowerCAmelCase             =       self.get_feature_extractor()
           __lowerCAmelCase             =       self.get_tokenizer()

           __lowerCAmelCase             =       ClapProcessor(tokenizer=__UpperCamelCase       ,    feature_extractor=__UpperCamelCase						)

           __lowerCAmelCase             =       "This is a test string"

           __lowerCAmelCase             =       processor(text=__UpperCamelCase						)

           __lowerCAmelCase             =       tokenizer(__UpperCamelCase						)

           for key in encoded_tok.keys():
                self.assertListEqual(encoded_tok[key]       ,    encoded_processor[key]						)


      def 			__UpperCAmelCase		(						self						)->						int:
           __lowerCAmelCase             =       self.get_feature_extractor()
           __lowerCAmelCase             =       self.get_tokenizer()

           __lowerCAmelCase             =       ClapProcessor(tokenizer=__UpperCamelCase       ,    feature_extractor=__UpperCamelCase						)

           __lowerCAmelCase             =       [[1, 4, 5, 8, 1, 0, 8], [3, 4, 3, 1, 1, 8, 9]]

           __lowerCAmelCase             =       processor.batch_decode(__UpperCamelCase						)
           __lowerCAmelCase             =       tokenizer.batch_decode(__UpperCamelCase						)

           self.assertListEqual(__UpperCamelCase       ,    __UpperCamelCase						)


      def 			__UpperCAmelCase		(						self						)->						Dict:
           __lowerCAmelCase             =       self.get_feature_extractor()
           __lowerCAmelCase             =       self.get_tokenizer()

           __lowerCAmelCase             =       ClapProcessor(tokenizer=__UpperCamelCase       ,    feature_extractor=__UpperCamelCase						)

           self.assertListEqual(
               processor.model_input_names[2:]       ,    feature_extractor.model_input_names       ,    msg="`processor` and `feature_extractor` model input names do not match"       ,    )






