


"""simple docstring"""




import unittest

from transformers import SpeechaTextaConfig
from transformers.testing_utils import is_torch_available, require_torch, torch_device

from ...generation.test_utils import GenerationTesterMixin
from ...test_configuration_common import ConfigTester
from ...test_modeling_common import ModelTesterMixin, ids_tensor
from ...test_pipeline_mixin import PipelineTesterMixin


if is_torch_available():
    import torch

    from transformers.models.speech_to_text_a.modeling_speech_to_text_a import (
        SpeechaTextaDecoder,
        SpeechaTextaForCausalLM,
    )







@require_torch
class       _lowercase			:


       """simple docstring"""




       def __init__(       self							:      Tuple ,				__lowerCamelCase							:      Any ,				__lowerCamelCase							:      List[str]=99 ,				__lowerCamelCase							:      List[Any]=13 ,				__lowerCamelCase							:      Dict=16 ,				__lowerCamelCase							:      List[str]=7 ,				__lowerCamelCase							:      Optional[Any]=True ,				__lowerCamelCase							:      List[Any]=True ,				__lowerCamelCase							:      Union[str, Any]=True ,				__lowerCamelCase							:      Optional[int]=False ,				__lowerCamelCase							:      Tuple=True ,				__lowerCamelCase							:      Optional[int]=2 ,				__lowerCamelCase							:      Any=32 ,				__lowerCamelCase							:      Any=4 ,				__lowerCamelCase							:      Any=4 ,				__lowerCamelCase							:      str=30 ,				__lowerCamelCase							:      Tuple=0 ,				__lowerCamelCase							:      List[Any]=1 ,				__lowerCamelCase							:      Any=2 ,				__lowerCamelCase							:      Union[str, Any]=None ,				):


             '''simple docstring'''



             lowerCamelCase__		:    Dict   =  parent
             lowerCamelCase__		:    Optional[int]   =  batch_size
             lowerCamelCase__		:    Union[str, Any]   =  decoder_seq_length
             # For common tests
             lowerCamelCase__		:    Optional[Any]   =  self.decoder_seq_length
             lowerCamelCase__		:    int   =  is_training
             lowerCamelCase__		:    List[str]   =  use_attention_mask
             lowerCamelCase__		:    List[Any]   =  use_labels

             lowerCamelCase__		:    Dict   =  vocab_size
             lowerCamelCase__		:    str   =  d_model
             lowerCamelCase__		:    Optional[Any]   =  d_model
             lowerCamelCase__		:    Optional[Any]   =  decoder_layers
             lowerCamelCase__		:    Tuple   =  decoder_layers
             lowerCamelCase__		:    Optional[Any]   =  decoder_ffn_dim
             lowerCamelCase__		:    List[str]   =  decoder_attention_heads
             lowerCamelCase__		:    int   =  decoder_attention_heads
             lowerCamelCase__		:    Union[str, Any]   =  eos_token_id
             lowerCamelCase__		:    List[str]   =  bos_token_id
             lowerCamelCase__		:    str   =  pad_token_id
             lowerCamelCase__		:    str   =  decoder_start_token_id
             lowerCamelCase__		:    int   =  use_cache
             lowerCamelCase__		:    Tuple   =  max_position_embeddings

             lowerCamelCase__		:    List[str]   =  None
             lowerCamelCase__		:    Any   =  decoder_seq_length
             lowerCamelCase__		:    Any   =  2
             lowerCamelCase__		:    Tuple   =  1





       def 						lowerCAmelCase					(       self							:      str	):


             '''simple docstring'''



             lowerCamelCase__		:    int   =  ids_tensor([self.batch_size, self.decoder_seq_length] ,				self.vocab_size	)

             lowerCamelCase__		:    Tuple   =  None
             if self.use_attention_mask:
                   lowerCamelCase__		:    Optional[int]   =  ids_tensor([self.batch_size, self.decoder_seq_length] ,				vocab_size=2	)

             lowerCamelCase__		:    Union[str, Any]   =  None
             if self.use_labels:
                   lowerCamelCase__		:    Tuple   =  ids_tensor([self.batch_size, self.decoder_seq_length] ,				self.vocab_size	)

             lowerCamelCase__		:    str   =  SpeechaTextaConfig(
                 vocab_size=self.vocab_size ,				d_model=self.d_model ,				decoder_layers=self.decoder_layers ,				decoder_ffn_dim=self.decoder_ffn_dim ,				decoder_attention_heads=self.decoder_attention_heads ,				eos_token_id=self.eos_token_id ,				bos_token_id=self.bos_token_id ,				use_cache=self.use_cache ,				pad_token_id=self.pad_token_id ,				decoder_start_token_id=self.decoder_start_token_id ,				max_position_embeddings=self.max_position_embeddings ,				)

             return (
                 config,
                 input_ids,
                 attention_mask,
                 lm_labels,
             )





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


             '''simple docstring'''



             lowerCamelCase__		:    Any   =  True
             lowerCamelCase__		:    Optional[int]   =  SpeechaTextaDecoder(config=__lowerCamelCase	).to(__lowerCamelCase	).eval()
             lowerCamelCase__		:    Optional[int]   =  input_ids[:2]

             input_ids[input_ids == 0] += 1
             # first forward pass
             lowerCamelCase__		:    List[str]   =  model(__lowerCamelCase ,				use_cache=__lowerCamelCase	)
             lowerCamelCase__		:    Any   =  model(__lowerCamelCase	)
             lowerCamelCase__		:    Any   =  model(__lowerCamelCase ,				use_cache=__lowerCamelCase	)

             self.parent.assertTrue(len(__lowerCamelCase	) == len(__lowerCamelCase	)	)
             self.parent.assertTrue(len(__lowerCamelCase	) == len(__lowerCamelCase	) + 1	)

             lowerCamelCase__		:    Any   =  outputs["past_key_values"]

             # create hypothetical next token and extent to next_input_ids
             lowerCamelCase__		:    Dict   =  ids_tensor((2, 1) ,				config.vocab_size - 1	) + 1

             # append to next input_ids and
             lowerCamelCase__		:    Optional[Any]   =  torch.cat([input_ids, next_tokens] ,				dim=-1	)

             print(__lowerCamelCase	)

             lowerCamelCase__		:    Dict   =  model(__lowerCamelCase	)["last_hidden_state"]
             lowerCamelCase__		:    Optional[Any]   =  model(__lowerCamelCase ,				past_key_values=__lowerCamelCase	)["last_hidden_state"]

             # select random slice
             lowerCamelCase__		:    Dict   =  ids_tensor((1,) ,				output_from_past.shape[-1]	).item()
             lowerCamelCase__		:    Tuple   =  output_from_no_past[:, next_input_ids.shape[-1] - 1, random_slice_idx].detach()
             lowerCamelCase__		:    Any   =  output_from_past[:, 0, random_slice_idx].detach()

             # test that outputs are equal for slice
             assert torch.allclose(__lowerCamelCase ,				__lowerCamelCase ,				atol=1E-3	)





       def 						lowerCAmelCase					(       self							:      Optional[Any]	):


             '''simple docstring'''



             lowerCamelCase__		:    str   =  self.prepare_config_and_inputs()
             (
                 lowerCamelCase__       
             )		:    Any   =  config_and_inputs

             lowerCamelCase__		:    Tuple   =  {
                 "input_ids": input_ids,
                 "attention_mask": attention_mask,
             }
             return config, inputs_dict







@require_torch
class       _lowercase			(							lowercase__							,  lowercase__							,  lowercase__							,  unittest.TestCase):


       """simple docstring"""




       A__ 						=      (SpeechaTextaDecoder, SpeechaTextaForCausalLM) if is_torch_available() else ()
       A__ 						=      (SpeechaTextaForCausalLM,) if is_torch_available() else ()
       A__ 						=      {"text-generation": SpeechaTextaForCausalLM} if is_torch_available() else {}
       A__ 						=      True
       A__ 						=      False





       def 						lowerCAmelCase					(       self							:      List[Any] ,				):


             '''simple docstring'''



             lowerCamelCase__		:    Optional[Any]   =  SpeechaTextaStandaloneDecoderModelTester(self ,				is_training=__lowerCamelCase	)
             lowerCamelCase__		:    int   =  ConfigTester(self ,				config_class=__lowerCamelCase	)





       def 						lowerCAmelCase					(       self							:      Tuple	):


             '''simple docstring'''



             pass





       def 						lowerCAmelCase					(       self							:      List[Any]	):


             '''simple docstring'''



             pass





       def 						lowerCAmelCase					(       self							:      Dict	):


             '''simple docstring'''



             pass





       def 						lowerCAmelCase					(       self							:      Tuple	):


             '''simple docstring'''



             self.config_tester.run_common_tests()





       def 						lowerCAmelCase					(       self							:      int	):


             '''simple docstring'''



             lowerCamelCase__		:    Optional[Any]   =  self.model_tester.prepare_config_and_inputs()
             self.model_tester.create_and_check_decoder_model_past(*__lowerCamelCase	)





       def 						lowerCAmelCase					(       self							:      Tuple	):


             '''simple docstring'''



             return






from urllib.error import HTTPError

from bsa import BeautifulSoup
from requests import exceptions, get

A				:   List[str]		= "https://www.wellrx.com/prescriptions/{0}/{1}/?freshSearch=true"

def 				lowercase_		(		_A      :   str   , _A      :   str						):

      """simple docstring"""




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

            lowerCamelCase__		:    List[str]   =  BASE_URL.format(_A   , _A						)
            lowerCamelCase__		:    int   =  get(_A						)

            # Is the response ok?
            response.raise_for_status()

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

            # This list will store the name and price.
            lowerCamelCase__		:    int   =  []

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

                        # Get price of the drug.
                        lowerCamelCase__		:    Union[str, Any]   =  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
    A				:   Any		= input("Enter drug name: ").strip()
    A				:   Union[str, Any]		= input("Enter zip code: ").strip()

    A				:   list | None		= 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:
            A				:   Dict		= pharmacy_price["pharmacy_name"]
            A				:   Optional[int]		= pharmacy_price["price"]

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


