# Copyright 2017 Google Inc.
#
# 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 collections import Counter, OrderedDict
import pandas as pd
import numpy as np
import random
import os
import pickle
import time

import tensorflow as tf

import matplotlib.pyplot as plt
from sklearn.manifold import TSNE
from scipy.spatial import distance


# this ensures TensorFlow doesn't use all GPU memory with a
# single graph (thus preventing other TF graphs from utilizing GPU)
GPU_MEM_CONFIG = tf.ConfigProto(gpu_options={'allow_growth': True})

class W2VModelDownload:
    def __init__(self, bq_project):
        # no-op
        self.bq_project = bq_project

    def download_w2v_model(self, landscape_bucket, model_name):
        from google.cloud import storage

        """
        Download a pre-trained Word2Vec model.
        :param models_url: The URL where models are stored
        :param model_name: The name of the model to download
        """

        checkpoint_list_file = '/'.join(['models', model_name, 'checkpoints', 'checkpoint'])
        if os.path.exists(checkpoint_list_file):
            print('Model {} already exists. Using local copy.'.format(model_name))
            return