
from manim import *


class  __magic_name__						(     _a):





	def 	_UpperCAmelCase						(		self	: int       ):
						UpperCAmelCase				   =  Rectangle(height=0.5    ,width=0.5       )
						UpperCAmelCase				   =  Rectangle(height=0.46    ,width=0.46       ).set_stroke(width=0       )

						UpperCAmelCase				   =  [mem.copy() for i in range(6       )]
						UpperCAmelCase				   =  [mem.copy() for i in range(6       )]
						UpperCAmelCase				   =  VGroup(*A_       ).arrange(A_    ,buff=0       )
						UpperCAmelCase				   =  VGroup(*A_       ).arrange(A_    ,buff=0       )
						UpperCAmelCase				   =  VGroup(A_    ,A_       ).arrange(A_    ,buff=0       )
						UpperCAmelCase				   =  Text("CPU"    ,font_size=2_4       )
						UpperCAmelCase				   =  Group(A_    ,A_       ).arrange(A_    ,buff=0.5    ,aligned_edge=A_       )
						cpu.move_to([-2.5, -0.5, 0]       )
						self.add(A_       )

						UpperCAmelCase				   =  [mem.copy() for i in range(1       )]
						UpperCAmelCase				   =  VGroup(*A_       ).arrange(A_    ,buff=0       )
						UpperCAmelCase				   =  Text("GPU"    ,font_size=2_4       )
						UpperCAmelCase				   =  Group(A_    ,A_       ).arrange(A_    ,buff=0.5    ,aligned_edge=A_       )
						gpu.align_to(A_    ,A_       )
						gpu.set_x(gpu.get_x() - 1       )

						self.add(A_       )

						UpperCAmelCase				   =  [mem.copy() for i in range(6       )]
						UpperCAmelCase				   =  VGroup(*A_       ).arrange(A_    ,buff=0       )

						UpperCAmelCase				   =  Text("Model"    ,font_size=2_4       )
						UpperCAmelCase				   =  Group(A_    ,A_       ).arrange(A_    ,buff=0.5    ,aligned_edge=A_       )
						model.move_to([3, -1.0, 0]       )

						self.play(
						    Create(A_    ,run_time=1       )    ,Create(A_    ,run_time=1       )    ,Create(A_    ,run_time=1       )    ,)

						UpperCAmelCase				   =  MarkupText(
						    f'''First, an empty model skeleton is loaded\ninto <span fgcolor=\'{YELLOW}\'>memory</span> without using much RAM.'''    ,font_size=2_4    ,)

						UpperCAmelCase				   =  Square(side_length=2.2       )
						key.move_to([-5, 2, 0]       )

						UpperCAmelCase				   =  MarkupText(
						    f'''<b>Key:</b>\n\n<span fgcolor=\'{YELLOW}\'>●</span> Empty Model'''    ,font_size=1_8    ,)

						key_text.move_to([-5, 2.4, 0]       )

						step_a.move_to([2, 2, 0]       )
						self.play(Write(A_    ,run_time=2.5       )    ,Write(A_       )    ,Write(A_       )       )

						self.add(A_       )

						UpperCAmelCase				   =  []
						UpperCAmelCase				   =  []
						UpperCAmelCase				   =  []
						for i, rect in enumerate(A_       ):
											UpperCAmelCase				   =  Rectangle(height=0.46    ,width=0.46       ).set_stroke(width=0.0       ).set_fill(A_    ,opacity=0.7       )
											cpu_target.move_to(A_       )
											cpu_target.generate_target()
											UpperCAmelCase				   =  0.46 / 4
											UpperCAmelCase				   =  0.46 / 3

											if i == 0:
																cpu_target.target.next_to(cpu_left_col_base[0].get_corner(DOWN + LEFT       )    ,buff=0.02    ,direction=A_       )
																cpu_target.target.set_x(cpu_target.target.get_x() + 0.1       )
											elif i == 3:
																cpu_target.target.next_to(cpu_targs[0].target    ,direction=A_    ,buff=0.0       )
											else:
																cpu_target.target.next_to(cpu_targs[i - 1].target    ,direction=A_    ,buff=0.0       )
											cpu_targs.append(A_       )

											first_animations.append(rect.animate(run_time=0.5       ).set_stroke(A_       )       )
											second_animations.append(MoveToTarget(A_    ,run_time=1.5       )       )

						self.play(*A_       )
						self.play(*A_       )

						self.wait()









import os
import tempfile
import unittest
import uuid
from pathlib import Path

from transformers.testing_utils import get_tests_dir, require_soundfile, require_torch, require_vision
from transformers.tools.agent_types import AgentAudio, AgentImage, AgentText
from transformers.utils import is_soundfile_availble, is_torch_available, is_vision_available


if is_torch_available():
    import torch

if is_soundfile_availble():
    import soundfile as sf

if is_vision_available():
    from PIL import Image






def 				_UpperCAmelCase			(    A=""     ):




   '''simple docstring'''

   UpperCAmelCase__						=tempfile.mkdtemp()
   return os.path.join(A				,							str(uuid.uuida()     ) + suffix     )

@require_soundfile
@require_torch
class     snake_case_		(   unittest.TestCase							):






 '''simple docstring'''





 def  __UpperCAmelCase						(  self		)	->       str:
    UpperCAmelCase__						=torch.rand(12,		dtype=torch.floataa		) - 0.5
    UpperCAmelCase__						=AgentAudio(A_		)
    UpperCAmelCase__						=str(agent_type.to_string()		)

    # Ensure that the tensor and the agent_type's tensor are the same
    self.assertTrue(torch.allclose(A_,		agent_type.to_raw(),		atol=1E-4		)		)

    del agent_type

    # Ensure the path remains even after the object deletion
    self.assertTrue(os.path.exists(A_		)		)

    # Ensure that the file contains the same value as the original tensor
    UpperCAmelCase__			,							UpperCAmelCase__						=sf.read(A_		)
    self.assertTrue(torch.allclose(A_,		torch.tensor(A_		),		atol=1E-4		)		)






 def  __UpperCAmelCase						(  self		)	->       Optional[Any]:
    UpperCAmelCase__						=torch.rand(12,		dtype=torch.floataa		) - 0.5
    UpperCAmelCase__						=get_new_path(suffix=".wav"		)
    sf.write(A_,		A_,		1_6000		)

    UpperCAmelCase__						=AgentAudio(A_		)

    self.assertTrue(torch.allclose(A_,		agent_type.to_raw(),		atol=1E-4		)		)
    self.assertEqual(agent_type.to_string(),		A_		)

@require_vision
@require_torch
class     snake_case_		(   unittest.TestCase							):






 '''simple docstring'''





 def  __UpperCAmelCase						(  self		)	->       int:
    UpperCAmelCase__						=torch.randint(0,		256,		(64, 64, 3)		)
    UpperCAmelCase__						=AgentImage(A_		)
    UpperCAmelCase__						=str(agent_type.to_string()		)

    # Ensure that the tensor and the agent_type's tensor are the same
    self.assertTrue(torch.allclose(A_,		agent_type._tensor,		atol=1E-4		)		)

    self.assertIsInstance(agent_type.to_raw(),		Image.Image		)

    # Ensure the path remains even after the object deletion
    del agent_type
    self.assertTrue(os.path.exists(A_		)		)

 def  __UpperCAmelCase						(  self		)	->       List[str]:
    UpperCAmelCase__						=Path(get_tests_dir("fixtures/tests_samples/COCO"		)		) / "000000039769.png"
    UpperCAmelCase__						=Image.open(A_		)
    UpperCAmelCase__						=AgentImage(A_		)

    self.assertTrue(path.samefile(agent_type.to_string()		)		)
    self.assertTrue(image == agent_type.to_raw()		)

    # Ensure the path remains even after the object deletion
    del agent_type
    self.assertTrue(os.path.exists(A_		)		)






 def  __UpperCAmelCase						(  self		)	->       Tuple:
    UpperCAmelCase__						=Path(get_tests_dir("fixtures/tests_samples/COCO"		)		) / "000000039769.png"
    UpperCAmelCase__						=Image.open(A_		)
    UpperCAmelCase__						=AgentImage(A_		)

    self.assertFalse(path.samefile(agent_type.to_string()		)		)
    self.assertTrue(image == agent_type.to_raw()		)

    # Ensure the path remains even after the object deletion
    del agent_type
    self.assertTrue(os.path.exists(A_		)		)

class     snake_case_		(   unittest.TestCase							):






 '''simple docstring'''





 def  __UpperCAmelCase						(  self		)	->       List[Any]:
    UpperCAmelCase__						="Hey!"
    UpperCAmelCase__						=AgentText(A_		)

    self.assertEqual(A_,		agent_type.to_string()		)
    self.assertEqual(A_,		agent_type.to_raw()		)
    self.assertEqual(A_,		A_		)



