






from typing import Dict, Optional, Tuple

import torch

def   SCREAMING_SNAKE_CASE_				(				__magic_name__   :    Optional[Any]   )						->     Optional[int]:






	"""simple docstring"""



	UpperCamelCase	:List[str]		=      boundaries[1] - boundaries[0]
	UpperCamelCase	:Dict		=      boundaries + step / 2
	UpperCamelCase	:Union[str, Any]		=      torch.cat([bin_centers, (bin_centers[-1] + step).unsqueeze(-1   )]      ,     dim=0   )
	return bin_centers

def   SCREAMING_SNAKE_CASE_				(				__magic_name__   :    str      ,     __magic_name__   :    List[Any]      ,     )						->     Union[str, Any]:






	"""simple docstring"""



	UpperCamelCase	:int		=      _calculate_bin_centers(UpperCAmelCase_   )
	return (
	    torch.sum(aligned_distance_error_probs * bin_centers      ,     dim=-1   ),
	    bin_centers[-1],
	)

def   SCREAMING_SNAKE_CASE_				(				__magic_name__   :    Union[str, Any]      ,     __magic_name__   :    List[Any] = 31      ,     __magic_name__   :    int = 64      ,     **__magic_name__   :    Tuple      ,     )						->     Dict:






	"""simple docstring"""



	UpperCamelCase	:Tuple		=      torch.linspace(0      ,     UpperCAmelCase_      ,     steps=(no_bins - 1)      ,     device=logits.device   )

	UpperCamelCase	:Optional[int]		=      torch.nn.functional.softmax(UpperCAmelCase_      ,     dim=-1   )
	UpperCamelCase	, UpperCamelCase	:List[str]		=      _calculate_expected_aligned_error(
	    alignment_confidence_breaks=UpperCAmelCase_      ,     aligned_distance_error_probs=UpperCAmelCase_      ,     )

	return {
	    "aligned_confidence_probs": aligned_confidence_probs,
	    "predicted_aligned_error": predicted_aligned_error,
	    "max_predicted_aligned_error": max_predicted_aligned_error,
	}

def   SCREAMING_SNAKE_CASE_				(				__magic_name__   :    Union[str, Any]      ,     __magic_name__   :    Union[str, Any] = None      ,     __magic_name__   :    Optional[Any] = 31      ,     __magic_name__   :    Dict = 64      ,     __magic_name__   :    Dict = 1E-8      ,     **__magic_name__   :    Dict      ,     )						->     str:






	"""simple docstring"""



	if residue_weights is None:
		UpperCamelCase	:Optional[int]		=      logits.new_ones(logits.shape[-2]   )

	UpperCamelCase	:int		=      torch.linspace(0      ,     UpperCAmelCase_      ,     steps=(no_bins - 1)      ,     device=logits.device   )

	UpperCamelCase	:Union[str, Any]		=      _calculate_bin_centers(UpperCAmelCase_   )
	torch.sum(UpperCAmelCase_   )
	UpperCamelCase	:Optional[Any]		=      logits.shape[-2]
	UpperCamelCase	:int		=      max(UpperCAmelCase_      ,     19   )

	UpperCamelCase	:List[Any]		=      1.24 * (clipped_n - 15) ** (1.0 / 3) - 1.8

	UpperCamelCase	:Any		=      torch.nn.functional.softmax(UpperCAmelCase_      ,     dim=-1   )

	UpperCamelCase	:Tuple		=      1.0 / (1 + (bin_centers**2) / (da**2))
	UpperCamelCase	:Tuple		=      torch.sum(probs * tm_per_bin      ,     dim=-1   )

	UpperCamelCase	:int		=      residue_weights / (eps + residue_weights.sum())
	UpperCamelCase	:List[str]		=      torch.sum(predicted_tm_term * normed_residue_mask      ,     dim=-1   )

	UpperCamelCase	:List[str]		=      per_alignment * residue_weights

	UpperCamelCase	:Optional[int]		=      (weighted == torch.max(UpperCAmelCase_   )).nonzero()[0]
	return per_alignment[tuple(UpperCAmelCase_   )]






# 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__)






