






'''simple docstring'''




from __future__ import annotations

import unittest

from transformers import AlbertConfig, is_tf_available
from transformers.models.auto import get_values
from transformers.testing_utils import require_tf, slow

from ...test_configuration_common import ConfigTester
from ...test_modeling_tf_common import TFModelTesterMixin, ids_tensor, random_attention_mask
from ...test_pipeline_mixin import PipelineTesterMixin


if is_tf_available():
    import tensorflow as tf

    from transformers import TF_MODEL_FOR_PRETRAINING_MAPPING
    from transformers.models.albert.modeling_tf_albert import (
        TF_ALBERT_PRETRAINED_MODEL_ARCHIVE_LIST,
        TFAlbertForMaskedLM,
        TFAlbertForMultipleChoice,
        TFAlbertForPreTraining,
        TFAlbertForQuestionAnswering,
        TFAlbertForSequenceClassification,
        TFAlbertForTokenClassification,
        TFAlbertModel,
    )

class      _UpperCAmelCase    :




   """simple docstring"""

   def __init__(	self				:			str   ,   __UpperCAmelCase				:			Optional[int]   ,   __UpperCAmelCase				:			List[Any]=13   ,   __UpperCAmelCase				:			Optional[int]=7   ,   __UpperCAmelCase				:			int=True   ,   __UpperCAmelCase				:			str=True   ,   __UpperCAmelCase				:			Optional[Any]=True   ,   __UpperCAmelCase				:			Union[str, Any]=True   ,   __UpperCAmelCase				:			Optional[int]=99   ,   __UpperCAmelCase				:			Tuple=16   ,   __UpperCAmelCase				:			Union[str, Any]=32   ,   __UpperCAmelCase				:			List[Any]=2   ,   __UpperCAmelCase				:			Any=4   ,   __UpperCAmelCase				:			Union[str, Any]=37   ,   __UpperCAmelCase				:			Any="gelu"   ,   __UpperCAmelCase				:			List[Any]=0.1   ,   __UpperCAmelCase				:			str=0.1   ,   __UpperCAmelCase				:			Union[str, Any]=512   ,   __UpperCAmelCase				:			Optional[Any]=16   ,   __UpperCAmelCase				:			List[Any]=2   ,   __UpperCAmelCase				:			List[str]=0.02   ,   __UpperCAmelCase				:			List[str]=3   ,   __UpperCAmelCase				:			List[str]=4   ,   __UpperCAmelCase				:			Any=None   ,   ):





         '''simple docstring'''





         _A      =			parent
         _A      =			13
         _A      =			7
         _A      =			True
         _A      =			True
         _A      =			True
         _A      =			True
         _A      =			99
         _A      =			16
         _A      =			32
         _A      =			2
         _A      =			4
         _A      =			37
         _A      =			"gelu"
         _A      =			0.1
         _A      =			0.1
         _A      =			512
         _A      =			16
         _A      =			2
         _A      =			0.02
         _A      =			3
         _A      =			4
         _A      =			None

   def 		lowerCAmelCase				(	self				:			Tuple	):





         '''simple docstring'''





         _A      =			ids_tensor([self.batch_size, self.seq_length]   ,   self.vocab_size	)

         _A      =			None
         if self.use_input_mask:
               _A      =			random_attention_mask([self.batch_size, self.seq_length]	)

         _A      =			None
         if self.use_token_type_ids:
               _A      =			ids_tensor([self.batch_size, self.seq_length]   ,   self.type_vocab_size	)

         _A      =			None
         _A      =			None
         _A      =			None
         if self.use_labels:
               _A      =			ids_tensor([self.batch_size]   ,   self.type_sequence_label_size	)
               _A      =			ids_tensor([self.batch_size, self.seq_length]   ,   self.num_labels	)
               _A      =			ids_tensor([self.batch_size]   ,   self.num_choices	)

         _A      =			AlbertConfig(
             vocab_size=self.vocab_size   ,   hidden_size=self.hidden_size   ,   embedding_size=self.embedding_size   ,   num_hidden_layers=self.num_hidden_layers   ,   num_attention_heads=self.num_attention_heads   ,   intermediate_size=self.intermediate_size   ,   hidden_act=self.hidden_act   ,   hidden_dropout_prob=self.hidden_dropout_prob   ,   attention_probs_dropout_prob=self.attention_probs_dropout_prob   ,   max_position_embeddings=self.max_position_embeddings   ,   type_vocab_size=self.type_vocab_size   ,   initializer_range=self.initializer_range   ,   )

         return config, input_ids, token_type_ids, input_mask, sequence_labels, token_labels, choice_labels

   def 		lowerCAmelCase				(	self				:			int   ,   __UpperCAmelCase				:			Any   ,   __UpperCAmelCase				:			Dict   ,   __UpperCAmelCase				:			int   ,   __UpperCAmelCase				:			Optional[int]   ,   __UpperCAmelCase				:			Optional[Any]   ,   __UpperCAmelCase				:			Dict   ,   __UpperCAmelCase				:			str	):





         '''simple docstring'''





         _A      =			TFAlbertModel(config=__UpperCAmelCase	)
         # inputs = {'input_ids': input_ids,
         #           'attention_mask': input_mask,
         #           'token_type_ids': token_type_ids}
         # sequence_output, pooled_output = model(**inputs)
         _A      =			{"input_ids": input_ids, "attention_mask": input_mask, "token_type_ids": token_type_ids}
         _A      =			model(__UpperCAmelCase	)

         _A      =			[input_ids, input_mask]
         _A      =			model(__UpperCAmelCase	)

         _A      =			model(__UpperCAmelCase	)

         self.parent.assertEqual(result.last_hidden_state.shape   ,   (self.batch_size, self.seq_length, self.hidden_size)	)
         self.parent.assertEqual(result.pooler_output.shape   ,   (self.batch_size, self.hidden_size)	)

   def 		lowerCAmelCase				(	self				:			Any   ,   __UpperCAmelCase				:			Any   ,   __UpperCAmelCase				:			Any   ,   __UpperCAmelCase				:			List[str]   ,   __UpperCAmelCase				:			str   ,   __UpperCAmelCase				:			Any   ,   __UpperCAmelCase				:			Optional[int]   ,   __UpperCAmelCase				:			Union[str, Any]	):





         '''simple docstring'''





         _A      =			self.num_labels
         _A      =			TFAlbertForPreTraining(config=__UpperCAmelCase	)
         _A      =			{"input_ids": input_ids, "attention_mask": input_mask, "token_type_ids": token_type_ids}
         _A      =			model(__UpperCAmelCase	)
         self.parent.assertEqual(result.prediction_logits.shape   ,   (self.batch_size, self.seq_length, self.vocab_size)	)
         self.parent.assertEqual(result.sop_logits.shape   ,   (self.batch_size, self.num_labels)	)

   def 		lowerCAmelCase				(	self				:			Optional[Any]   ,   __UpperCAmelCase				:			Union[str, Any]   ,   __UpperCAmelCase				:			List[str]   ,   __UpperCAmelCase				:			Optional[Any]   ,   __UpperCAmelCase				:			Optional[int]   ,   __UpperCAmelCase				:			int   ,   __UpperCAmelCase				:			Tuple   ,   __UpperCAmelCase				:			Dict	):





         '''simple docstring'''





         _A      =			TFAlbertForMaskedLM(config=__UpperCAmelCase	)
         _A      =			{"input_ids": input_ids, "attention_mask": input_mask, "token_type_ids": token_type_ids}
         _A      =			model(__UpperCAmelCase	)
         self.parent.assertEqual(result.logits.shape   ,   (self.batch_size, self.seq_length, self.vocab_size)	)

   def 		lowerCAmelCase				(	self				:			Tuple   ,   __UpperCAmelCase				:			Any   ,   __UpperCAmelCase				:			Any   ,   __UpperCAmelCase				:			Union[str, Any]   ,   __UpperCAmelCase				:			str   ,   __UpperCAmelCase				:			List[Any]   ,   __UpperCAmelCase				:			Dict   ,   __UpperCAmelCase				:			List[Any]	):





         '''simple docstring'''





         _A      =			self.num_labels
         _A      =			TFAlbertForSequenceClassification(config=__UpperCAmelCase	)
         _A      =			{"input_ids": input_ids, "attention_mask": input_mask, "token_type_ids": token_type_ids}
         _A      =			model(__UpperCAmelCase	)
         self.parent.assertEqual(result.logits.shape   ,   (self.batch_size, self.num_labels)	)

   def 		lowerCAmelCase				(	self				:			List[Any]   ,   __UpperCAmelCase				:			Optional[Any]   ,   __UpperCAmelCase				:			Union[str, Any]   ,   __UpperCAmelCase				:			Optional[int]   ,   __UpperCAmelCase				:			Any   ,   __UpperCAmelCase				:			List[str]   ,   __UpperCAmelCase				:			int   ,   __UpperCAmelCase				:			Tuple	):





         '''simple docstring'''





         _A      =			TFAlbertForQuestionAnswering(config=__UpperCAmelCase	)
         _A      =			{"input_ids": input_ids, "attention_mask": input_mask, "token_type_ids": token_type_ids}
         _A      =			model(__UpperCAmelCase	)
         self.parent.assertEqual(result.start_logits.shape   ,   (self.batch_size, self.seq_length)	)
         self.parent.assertEqual(result.end_logits.shape   ,   (self.batch_size, self.seq_length)	)

   def 		lowerCAmelCase				(	self				:			List[Any]   ,   __UpperCAmelCase				:			Optional[int]   ,   __UpperCAmelCase				:			Union[str, Any]   ,   __UpperCAmelCase				:			Dict   ,   __UpperCAmelCase				:			Optional[int]   ,   __UpperCAmelCase				:			Union[str, Any]   ,   __UpperCAmelCase				:			int   ,   __UpperCAmelCase				:			List[Any]	):





         '''simple docstring'''





         _A      =			self.num_choices
         _A      =			TFAlbertForMultipleChoice(config=__UpperCAmelCase	)
         _A      =			tf.tile(tf.expand_dims(__UpperCAmelCase   ,   1	)   ,   (1, self.num_choices, 1)	)
         _A      =			tf.tile(tf.expand_dims(__UpperCAmelCase   ,   1	)   ,   (1, self.num_choices, 1)	)
         _A      =			tf.tile(tf.expand_dims(__UpperCAmelCase   ,   1	)   ,   (1, self.num_choices, 1)	)
         _A      =			{
             "input_ids": multiple_choice_inputs_ids,
             "attention_mask": multiple_choice_input_mask,
             "token_type_ids": multiple_choice_token_type_ids,
         }
         _A      =			model(__UpperCAmelCase	)
         self.parent.assertListEqual(list(result["logits"].shape	)   ,   [self.batch_size, self.num_choices]	)

   def 		lowerCAmelCase				(	self				:			Union[str, Any]   ,   __UpperCAmelCase				:			List[Any]   ,   __UpperCAmelCase				:			List[str]   ,   __UpperCAmelCase				:			Any   ,   __UpperCAmelCase				:			Optional[int]   ,   __UpperCAmelCase				:			Optional[int]   ,   __UpperCAmelCase				:			Tuple   ,   __UpperCAmelCase				:			Any	):





         '''simple docstring'''





         _A      =			self.num_labels
         _A      =			TFAlbertForTokenClassification(config=__UpperCAmelCase	)
         _A      =			{
             "input_ids": input_ids,
             "attention_mask": input_mask,
             "token_type_ids": token_type_ids,
         }
         _A      =			model(__UpperCAmelCase	)
         self.parent.assertListEqual(list(result["logits"].shape	)   ,   [self.batch_size, self.seq_length, self.num_labels]	)

   def 		lowerCAmelCase				(	self				:			Optional[int]	):





         '''simple docstring'''





         _A      =			self.prepare_config_and_inputs()
         (
             (
             _A
         )  ,			(
             _A
         )  ,			(
             _A
         )  ,			(
             _A
         )  ,			(
             _A
         )  ,			(
             _A
         )  ,			(
             _A
         )  ,			
         )      =			config_and_inputs
         _A      =			{"input_ids": input_ids, "token_type_ids": token_type_ids, "attention_mask": input_mask}
         return config, inputs_dict





@require_tf
class      _UpperCAmelCase    (  snake_case_							,					snake_case_							,					unittest.TestCase		):




   """simple docstring"""

   snake_case					       =		(
       (
           TFAlbertModel,
           TFAlbertForPreTraining,
           TFAlbertForMaskedLM,
           TFAlbertForSequenceClassification,
           TFAlbertForQuestionAnswering,
           TFAlbertForTokenClassification,
           TFAlbertForMultipleChoice,
       )
       if is_tf_available()
       else ()
   )
   snake_case					       =		(
       {
           '''feature-extraction''': TFAlbertModel,
           '''fill-mask''': TFAlbertForMaskedLM,
           '''question-answering''': TFAlbertForQuestionAnswering,
           '''text-classification''': TFAlbertForSequenceClassification,
           '''token-classification''': TFAlbertForTokenClassification,
           '''zero-shot''': TFAlbertForSequenceClassification,
       }
       if is_tf_available()
       else {}
   )
   snake_case					       =		False
   snake_case					       =		False

   def 		lowerCAmelCase				(	self				:			List[str]   ,   __UpperCAmelCase				:			Any   ,   __UpperCAmelCase				:			Any   ,   __UpperCAmelCase				:			Optional[int]=False	):





         '''simple docstring'''





         _A      =			super()._prepare_for_class(__UpperCAmelCase   ,   __UpperCAmelCase   ,   return_labels=__UpperCAmelCase	)

         if return_labels:
               if model_class in get_values(__UpperCAmelCase	):
                     _A      =			tf.zeros(self.model_tester.batch_size   ,   dtype=tf.intaa	)

         return inputs_dict

   def 		lowerCAmelCase				(	self				:			Optional[Any]	):





         '''simple docstring'''





         _A      =			TFAlbertModelTester(self	)
         _A      =			ConfigTester(self   ,   config_class=__UpperCAmelCase   ,   hidden_size=37	)

   def 		lowerCAmelCase				(	self				:			List[Any]	):





         '''simple docstring'''





         self.config_tester.run_common_tests()

   def 		lowerCAmelCase				(	self				:			List[str]	):





         '''simple docstring'''





         _A      =			self.model_tester.prepare_config_and_inputs()
         self.model_tester.create_and_check_albert_model(*__UpperCAmelCase	)

   def 		lowerCAmelCase				(	self				:			str	):





         '''simple docstring'''





         _A      =			self.model_tester.prepare_config_and_inputs()
         self.model_tester.create_and_check_albert_for_pretraining(*__UpperCAmelCase	)

   def 		lowerCAmelCase				(	self				:			Any	):





         '''simple docstring'''





         _A      =			self.model_tester.prepare_config_and_inputs()
         self.model_tester.create_and_check_albert_for_masked_lm(*__UpperCAmelCase	)

   def 		lowerCAmelCase				(	self				:			Optional[int]	):





         '''simple docstring'''





         _A      =			self.model_tester.prepare_config_and_inputs()
         self.model_tester.create_and_check_albert_for_multiple_choice(*__UpperCAmelCase	)

   def 		lowerCAmelCase				(	self				:			Optional[int]	):





         '''simple docstring'''





         _A      =			self.model_tester.prepare_config_and_inputs()
         self.model_tester.create_and_check_albert_for_sequence_classification(*__UpperCAmelCase	)

   def 		lowerCAmelCase				(	self				:			Tuple	):





         '''simple docstring'''





         _A      =			self.model_tester.prepare_config_and_inputs()
         self.model_tester.create_and_check_albert_for_question_answering(*__UpperCAmelCase	)

   @slow
   def 		lowerCAmelCase				(	self				:			Any	):





         '''simple docstring'''





         for model_name in TF_ALBERT_PRETRAINED_MODEL_ARCHIVE_LIST[:1]:
               _A      =			TFAlbertModel.from_pretrained(__UpperCAmelCase	)
               self.assertIsNotNone(__UpperCAmelCase	)





@require_tf
class      _UpperCAmelCase    (  unittest.TestCase		):




   """simple docstring"""

   @slow
   def 		lowerCAmelCase				(	self				:			Optional[Any]	):





         '''simple docstring'''





         _A      =			TFAlbertForPreTraining.from_pretrained("albert-base-v2"	)
         _A      =			tf.constant([[0, 1, 2, 3, 4, 5]]	)
         _A      =			model(__UpperCAmelCase	)[0]

         _A      =			[1, 6, 30000]
         self.assertEqual(output.shape   ,   __UpperCAmelCase	)

         _A      =			tf.constant(
             [
                 [
                     [4.595668, 0.74462754, -1.818147],
                     [4.5954347, 0.7454184, -1.8188258],
                     [4.5954905, 0.7448235, -1.8182316],
                 ]
             ]	)
         tf.debugging.assert_near(output[:, :3, :3]   ,   __UpperCAmelCase   ,   atol=1E-4	)













'''simple docstring'''




from urllib.error import HTTPError

from bsa import BeautifulSoup
from requests import exceptions, get

lowerCamelCase_							      =      '''https://www.wellrx.com/prescriptions/{0}/{1}/?freshSearch=true'''

def       __lowercase		(    __lowercase     ,						__lowercase ) ->		list | None:

      '''simple docstring'''


      try:
            # Has user provided both inputs?
            if not drug_name or not zip_code:
                  return None

            _A      =			BASE_URL.format(__lowercase     ,						__lowercase )
            _A      =			get(__lowercase )

            # Is the response ok?
            response.raise_for_status()

            # Scrape the data using bs4
            _A      =			BeautifulSoup(response.text     ,						"html.parser" )

            # This list will store the name and price.
            _A      =			[]

            # Fetch all the grids that contains the items.
            _A      =			soup.find_all("div"     ,						{"class": "grid-x pharmCard"} )
            if grid_list and len(__lowercase ) > 0:
                  for grid in grid_list:
                        # Get the pharmacy price.
                        _A      =			grid.find("p"     ,						{"class": "list-title"} ).text

                        # Get price of the drug.
                        _A      =			grid.find("span"     ,						{"p", "price price-large"} ).text

                        pharmacy_price_list.append(
                            {
                                "pharmacy_name": pharmacy_name,
                                "price": price,
                            } )

            return pharmacy_price_list

      except (HTTPError, exceptions.RequestException, ValueError):
            return None


if __name__ == "__main__":
    # Enter a drug name and a zip code
    lowerCamelCase_							      =      input('''Enter drug name: ''').strip()
    lowerCamelCase_							      =      input('''Enter zip code: ''').strip()

    lowerCamelCase_							      =      fetch_pharmacy_and_price_list(
        drug_name, zip_code
    )

    if pharmacy_price_list:
        print(F"""\nSearch results for {drug_name} at location {zip_code}:""")
        for pharmacy_price in pharmacy_price_list:
            lowerCamelCase_							      =      pharmacy_price['''pharmacy_name''']
            lowerCamelCase_							      =      pharmacy_price['''price''']

            print(F"""Pharmacy: {name} Price: {price}""")
    else:
        print(F"""No results found for {drug_name}""")





