from flask import Flask
from flask_restful import Api
from flask_sqlalchemy import SQLAlchemy
from flask_jwt_extended import JWTManager

def warn(*args, **kwargs):
    pass
import warnings
warnings.warn = warn


app = Flask(__name__)
api = Api(app)
import os
app.config['SQLALCHEMY_DATABASE_URI'] = 'sqlite:///app.db'
app.config['SQLALCHEMY_TRACK_MODIFICATIONS'] = False
app.config['SECRET_KEY'] = 'some-secret-string'
app.config['UPLOAD_FOLDER'] = 'tmp/upload'
os.environ["CUDA_VISIBLE_DEVICES"] = "2"
db = SQLAlchemy(app)

app.config['JWT_SECRET_KEY'] = 'jwt-secret-string'
jwt = JWTManager(app)

app.config['JWT_BLACKLIST_ENABLED'] = True
app.config['JWT_BLACKLIST_TOKEN_CHECKS'] = ['access', 'refresh']
@jwt.token_in_blacklist_loader
def check_if_token_in_blacklist(decrypted_token):
    jti = decrypted_token['jti']
    return models.RevokedTokenModel.is_jti_blacklisted(jti)


import views, models, resources

api.add_resource(resources.Whois,'/whois')
api.add_resource(resources.Upload_image,'/upload/image')
api.add_resource(resources.Train,'/train')
api.add_resource(resources.Clock,'/clock')
api.add_resource(resources.Insert_employee,'/insert')



@app.before_first_request
def create_tables():
    db.create_all()

if __name__ == '__main__':
#     print(('* Loading Keras model and Flask starting server...'
#         'please wait until server has fully started'))
#     perload_model()
    app.run()
    
# app.run(host='0.0.0.0', port=8000, debug=True)