


'''simple docstring'''

import unittest

from transformers import is_vision_available
from transformers.pipelines import pipeline
from transformers.testing_utils import (
    is_pipeline_test,
    nested_simplify,
    require_tf,
    require_torch,
    require_vision,
    slow,
)

from .test_pipelines_common import ANY


if is_vision_available():
     from PIL import Image
else:





     class      snake_case    :





       """simple docstring"""




       @staticmethod
       def   snake_case		(    *UpperCamelCase			,  **UpperCamelCase     ):







        """simple docstring"""
        pass





@is_pipeline_test
@require_vision
class      snake_case    (    unittest.TestCase			):





  """simple docstring"""




  @require_torch
  def   snake_case		(    self     ):







   """simple docstring"""
   lowerCamelCase_      =  pipeline(
       model="hf-internal-testing/tiny-random-clip-zero-shot-image-classification"			,  )
   lowerCamelCase_      =  Image.open("./tests/fixtures/tests_samples/COCO/000000039769.png"     )
   lowerCamelCase_      =  image_classifier(_UpperCAmelCase			,  candidate_labels=["a", "b", "c"]     )

   # The floating scores are so close, we enter floating error approximation and the order is not guaranteed across
   # python and torch versions.
   self.assertIn(
       nested_simplify(_UpperCAmelCase     )			,  [
           [{"score": 0.333, "label": "a"}, {"score": 0.333, "label": "b"}, {"score": 0.333, "label": "c"}],
           [{"score": 0.333, "label": "a"}, {"score": 0.333, "label": "c"}, {"score": 0.333, "label": "b"}],
       ]			,  )

   lowerCamelCase_      =  image_classifier([image] * 5			,  candidate_labels=["A", "B", "C"]			,  batch_size=2     )
   self.assertEqual(
       nested_simplify(_UpperCAmelCase     )			,  [
           [
               {"score": 0.333, "label": ANY(_UpperCAmelCase     )},
               {"score": 0.333, "label": ANY(_UpperCAmelCase     )},
               {"score": 0.333, "label": ANY(_UpperCAmelCase     )},
           ],
           [
               {"score": 0.333, "label": ANY(_UpperCAmelCase     )},
               {"score": 0.333, "label": ANY(_UpperCAmelCase     )},
               {"score": 0.333, "label": ANY(_UpperCAmelCase     )},
           ],
           [
               {"score": 0.333, "label": ANY(_UpperCAmelCase     )},
               {"score": 0.333, "label": ANY(_UpperCAmelCase     )},
               {"score": 0.333, "label": ANY(_UpperCAmelCase     )},
           ],
           [
               {"score": 0.333, "label": ANY(_UpperCAmelCase     )},
               {"score": 0.333, "label": ANY(_UpperCAmelCase     )},
               {"score": 0.333, "label": ANY(_UpperCAmelCase     )},
           ],
           [
               {"score": 0.333, "label": ANY(_UpperCAmelCase     )},
               {"score": 0.333, "label": ANY(_UpperCAmelCase     )},
               {"score": 0.333, "label": ANY(_UpperCAmelCase     )},
           ],
       ]			,  )






  @require_tf
  def   snake_case		(    self     ):







   """simple docstring"""
   lowerCamelCase_      =  pipeline(
       model="hf-internal-testing/tiny-random-clip-zero-shot-image-classification"			,  framework="tf"     )
   lowerCamelCase_      =  Image.open("./tests/fixtures/tests_samples/COCO/000000039769.png"     )
   lowerCamelCase_      =  image_classifier(_UpperCAmelCase			,  candidate_labels=["a", "b", "c"]     )

   self.assertEqual(
       nested_simplify(_UpperCAmelCase     )			,  [{"score": 0.333, "label": "a"}, {"score": 0.333, "label": "b"}, {"score": 0.333, "label": "c"}]			,  )

   lowerCamelCase_      =  image_classifier([image] * 5			,  candidate_labels=["A", "B", "C"]			,  batch_size=2     )
   self.assertEqual(
       nested_simplify(_UpperCAmelCase     )			,  [
           [
               {"score": 0.333, "label": ANY(_UpperCAmelCase     )},
               {"score": 0.333, "label": ANY(_UpperCAmelCase     )},
               {"score": 0.333, "label": ANY(_UpperCAmelCase     )},
           ],
           [
               {"score": 0.333, "label": ANY(_UpperCAmelCase     )},
               {"score": 0.333, "label": ANY(_UpperCAmelCase     )},
               {"score": 0.333, "label": ANY(_UpperCAmelCase     )},
           ],
           [
               {"score": 0.333, "label": ANY(_UpperCAmelCase     )},
               {"score": 0.333, "label": ANY(_UpperCAmelCase     )},
               {"score": 0.333, "label": ANY(_UpperCAmelCase     )},
           ],
           [
               {"score": 0.333, "label": ANY(_UpperCAmelCase     )},
               {"score": 0.333, "label": ANY(_UpperCAmelCase     )},
               {"score": 0.333, "label": ANY(_UpperCAmelCase     )},
           ],
           [
               {"score": 0.333, "label": ANY(_UpperCAmelCase     )},
               {"score": 0.333, "label": ANY(_UpperCAmelCase     )},
               {"score": 0.333, "label": ANY(_UpperCAmelCase     )},
           ],
       ]			,  )






  @slow
  @require_torch
  def   snake_case		(    self     ):







   """simple docstring"""
   lowerCamelCase_      =  pipeline(
       task="zero-shot-image-classification"			,  model="openai/clip-vit-base-patch32"			,  )
   # This is an image of 2 cats with remotes and no planes
   lowerCamelCase_      =  Image.open("./tests/fixtures/tests_samples/COCO/000000039769.png"     )
   lowerCamelCase_      =  image_classifier(_UpperCAmelCase			,  candidate_labels=["cat", "plane", "remote"]     )

   self.assertEqual(
       nested_simplify(_UpperCAmelCase     )			,  [
           {"score": 0.511, "label": "remote"},
           {"score": 0.485, "label": "cat"},
           {"score": 0.004, "label": "plane"},
       ]			,  )

   lowerCamelCase_      =  image_classifier([image] * 5			,  candidate_labels=["cat", "plane", "remote"]			,  batch_size=2     )
   self.assertEqual(
       nested_simplify(_UpperCAmelCase     )			,  [
           [
               {"score": 0.511, "label": "remote"},
               {"score": 0.485, "label": "cat"},
               {"score": 0.004, "label": "plane"},
           ],
       ]
       * 5			,  )







  @slow
  @require_tf
  def   snake_case		(    self     ):







   """simple docstring"""
   lowerCamelCase_      =  pipeline(
       task="zero-shot-image-classification"			,  model="openai/clip-vit-base-patch32"			,  framework="tf"     )
   # This is an image of 2 cats with remotes and no planes
   lowerCamelCase_      =  Image.open("./tests/fixtures/tests_samples/COCO/000000039769.png"     )
   lowerCamelCase_      =  image_classifier(_UpperCAmelCase			,  candidate_labels=["cat", "plane", "remote"]     )
   self.assertEqual(
       nested_simplify(_UpperCAmelCase     )			,  [
           {"score": 0.511, "label": "remote"},
           {"score": 0.485, "label": "cat"},
           {"score": 0.004, "label": "plane"},
       ]			,  )

   lowerCamelCase_      =  image_classifier([image] * 5			,  candidate_labels=["cat", "plane", "remote"]			,  batch_size=2     )
   self.assertEqual(
       nested_simplify(_UpperCAmelCase     )			,  [
           [
               {"score": 0.511, "label": "remote"},
               {"score": 0.485, "label": "cat"},
               {"score": 0.004, "label": "plane"},
           ],
       ]
       * 5			,  )










'''simple docstring'''




import numpy as np
import pandas as pd
from sklearn.preprocessing import MinMaxScaler
from tensorflow.keras.layers import LSTM, Dense
from tensorflow.keras.models import Sequential

if __name__ == "__main__":
  lowercase__    :      List[Any]						=    pd.read_csv('''sample_data.csv''', header=None)
  lowercase__    :      Union[str, Any]						=    df.shape[:1][0]
  # If you're using some other dataset input the target column
  lowercase__    :      Any						=    df.iloc[:, 1:2]
  lowercase__    :      int						=    actual_data.values.reshape(len_data, 1)
  lowercase__    :      int						=    MinMaxScaler().fit_transform(actual_data)
  lowercase__    :      Dict						=    10
  lowercase__    :      List[str]						=    5
  lowercase__    :      Dict						=    20
  lowercase__    :      Dict						=    len_data - periods * look_back
  lowercase__    :      Any						=    actual_data[:division]
  lowercase__    :      Optional[int]						=    actual_data[division - look_back :]
  lowercase__	,							lowercase__    :      Optional[Any]						=    [], []
  lowercase__	,							lowercase__    :      Tuple						=    [], []

  for i in range(0, len(train_data) - forward_days - look_back + 1):
    train_x.append(train_data[i : i + look_back])
    train_y.append(train_data[i + look_back : i + look_back + forward_days])
  for i in range(0, len(test_data) - forward_days - look_back + 1):
    test_x.append(test_data[i : i + look_back])
    test_y.append(test_data[i + look_back : i + look_back + forward_days])
  lowercase__    :      List[Any]						=    np.array(train_x)
  lowercase__    :      List[Any]						=    np.array(test_x)
  lowercase__    :      str						=    np.array([list(i.ravel()) for i in train_y])
  lowercase__    :      Any						=    np.array([list(i.ravel()) for i in test_y])

  lowercase__    :      Optional[Any]						=    Sequential()
  model.add(LSTM(1_28, input_shape=(look_back, 1), return_sequences=True))
  model.add(LSTM(64, input_shape=(1_28, 1)))
  model.add(Dense(forward_days))
  model.compile(loss='''mean_squared_error''', optimizer='''adam''')
  lowercase__    :      Tuple						=    model.fit(
      x_train, y_train, epochs=1_50, verbose=1, shuffle=True, batch_size=4
  )
  lowercase__    :      int						=    model.predict(x_test)