




from __future__ import annotations
def 							__lowerCAmelCase			(UpperCAmelCase_ ,     UpperCAmelCase_ ,     UpperCAmelCase_		):
    assert n > 1 and a > 0 and greatest_common_divisor(UpperCAmelCase_ ,     UpperCAmelCase_		) == 1
    ((a__)			,		(a__)			,		(a__))  			=							extended_gcd(UpperCAmelCase_ ,     UpperCAmelCase_		)  # Implemented below
    a__  			=							(b * s) % n
    return x
def 							__lowerCAmelCase			(UpperCAmelCase_ ,     UpperCAmelCase_		):
    ((a__)			,		(a__))  			=							extended_euclid(UpperCAmelCase_ ,     UpperCAmelCase_		)  # Implemented below
    if b < 0:
        a__  			=							(b % n + n) % n
    return b
def 							__lowerCAmelCase			(UpperCAmelCase_ ,     UpperCAmelCase_ ,     UpperCAmelCase_		):
    a__  			=							invert_modulo(UpperCAmelCase_ ,     UpperCAmelCase_		)
    a__  			=							(b * s) % n
    return x
def 							__lowerCAmelCase			(UpperCAmelCase_ ,     UpperCAmelCase_		):
    assert a >= 0 and b >= 0

    if b == 0:
        a__			,		a__			,		a__  			=							a, 1, 0
    else:
        ((a__)			,		(a__)			,		(a__))  			=							extended_gcd(UpperCAmelCase_ ,     a % b		)
        a__  			=							q
        a__  			=							p - q * (a // b)

    assert a % d == 0 and b % d == 0
    assert d == a * x + b * y

    return (d, x, y)
def 							__lowerCAmelCase			(UpperCAmelCase_ ,     UpperCAmelCase_		):
    if b == 0:
        return (1, 0)
    ((a__)			,		(a__))  			=							extended_euclid(UpperCAmelCase_ ,     a % b		)
    a__  			=							a // b
    return (y, x - k * y)
def 							__lowerCAmelCase			(UpperCAmelCase_ ,     UpperCAmelCase_		):
    if a < b:
        a__			,		a__  			=							b, a

    while a % b != 0:
        a__			,		a__  			=							b, a % b

    return b


if __name__ == "__main__":
 from doctest import testmod

 testmod(name='''modular_division''', verbose=True)
 testmod(name='''modular_division2''', verbose=True)
 testmod(name='''invert_modulo''', verbose=True)
 testmod(name='''extended_gcd''', verbose=True)
 testmod(name='''extended_euclid''', verbose=True)
 testmod(name='''greatest_common_divisor''', verbose=True)












# Copyright 2023 The HuggingFace Inc. team. All rights reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#     http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
from typing import TYPE_CHECKING

from ..utils import (
    OptionalDependencyNotAvailable,
    _LazyModule,
    is_torch_available,
)


SCREAMING_SNAKE_CASE_    :       int       =							{
    '''agents''': ['''Agent''', '''AzureOpenAiAgent''', '''HfAgent''', '''LocalAgent''', '''OpenAiAgent'''],
    '''base''': ['''PipelineTool''', '''RemoteTool''', '''Tool''', '''launch_gradio_demo''', '''load_tool'''],
}

try:
 if not is_torch_available():
  raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
 pass
else:
 SCREAMING_SNAKE_CASE_    :       int       =							['''DocumentQuestionAnsweringTool''']
 SCREAMING_SNAKE_CASE_    :       List[Any]       =							['''ImageCaptioningTool''']
 SCREAMING_SNAKE_CASE_    :       Union[str, Any]       =							['''ImageQuestionAnsweringTool''']
 SCREAMING_SNAKE_CASE_    :       str       =							['''ImageSegmentationTool''']
 SCREAMING_SNAKE_CASE_    :       Any       =							['''SpeechToTextTool''']
 SCREAMING_SNAKE_CASE_    :       Union[str, Any]       =							['''TextClassificationTool''']
 SCREAMING_SNAKE_CASE_    :       List[Any]       =							['''TextQuestionAnsweringTool''']
 SCREAMING_SNAKE_CASE_    :       Dict       =							['''TextSummarizationTool''']
 SCREAMING_SNAKE_CASE_    :       Optional[int]       =							['''TextToSpeechTool''']
 SCREAMING_SNAKE_CASE_    :       Dict       =							['''TranslationTool''']

if TYPE_CHECKING:
 from .agents import Agent, AzureOpenAiAgent, HfAgent, LocalAgent, OpenAiAgent
 from .base import PipelineTool, RemoteTool, Tool, launch_gradio_demo, load_tool

 try:
  if not is_torch_available():
   raise OptionalDependencyNotAvailable()
 except OptionalDependencyNotAvailable:
  pass
 else:
  from .document_question_answering import DocumentQuestionAnsweringTool
  from .image_captioning import ImageCaptioningTool
  from .image_question_answering import ImageQuestionAnsweringTool
  from .image_segmentation import ImageSegmentationTool
  from .speech_to_text import SpeechToTextTool
  from .text_classification import TextClassificationTool
  from .text_question_answering import TextQuestionAnsweringTool
  from .text_summarization import TextSummarizationTool
  from .text_to_speech import TextToSpeechTool
  from .translation import TranslationTool
else:
 import sys

 SCREAMING_SNAKE_CASE_    :       Optional[Any]       =							_LazyModule(__name__, globals()['''__file__'''], _import_structure, module_spec=__spec__)






