text: import os
  import sqlite3
  import uuid
  
  from flask import Flask, request, session, g, redirect, url_for, abort, \
       render_template, flash
  from flask import send_from_directory
  from werkzeug.utils import secure_filename
  
  UPLOAD_FOLDER = '../uploads'
  ALLOWED_EXTENSIONS = set(['txt', 'pdf', 'png', 'jpg', 'jpeg', 'gif'])
  
  app = Flask(__name__) # create the application instance :)
  app.config.from_object(__name__) # load config from this file , flaskr.py
  
  # Load default config and override config from an environment variable
  app.config.update(dict(
      DATABASE=os.path.join(app.root_path, 'keras_image_projects.db'),
      SECRET_KEY='development-key',
      USERNAME='admin',
      PASSWORD='admin'
  ))
  app.config.from_envvar('FLASKR_SETTINGS', silent=True)
  app.config['MAX_CONTENT_LENGTH'] = 16 * 1024 * 1024
  
  
  def connect_db():
      """Connects to the specific database."""
      rv = sqlite3.connect(app.config['DATABASE'])
      rv.row_factory = sqlite3.Row
      return rv
  
  
  def get_db():
      """Opens a new database connection if there is none yet for the
      current application context.
      """
      if not hasattr(g, 'sqlite_db'):
          g.sqlite_db = connect_db()
      return g.sqlite_db
  
  
  @app.teardown_appcontext
  def close_db(error):
      """Closes the database again at the end of the request."""
      if hasattr(g, 'sqlite_db'):
          g.sqlite_db.close()
  
  
  def init_db():
      db = get_db()
      with app.open_resource('schema.sql', mode='r') as f:
          db.cursor().executescript(f.read())
      db.commit()
  
  
  @app.cli.command('initdb')
  def initdb_command():
      """Initializes the database."""
      init_db()
      print('Initialized the database.')
  
  
  @app.route('/')
  def show_entries():
      db = get_db()
      cur = db.execute('select id, description, name from projects order by id desc')
      entries = cur.fetchall()
      return render_template('show_entries.html', entries=entries)
  
  
  @app.route('/add', methods=['POST'])
  def add_entry():
      if not session.get('logged_in'):
          abort(401)
      db = get_db()
      db.execute('insert into projects (name, description) values (?, ?)',
                   [request.form['name'], request.form['description'], str(uuid.uuid4())])
      db.commit()
      flash('New entry was successfully posted')
      return redirect(url_for('show_entries'))
  
  
  @app.route('/login', methods=['GET', 'POST'])
  def login():
      error = None
      if request.method == 'POST':
          if request.form['username'] != app.config['USERNAME']:
              error = 'Invalid username'
          elif request.form['password'] != app.config['PASSWORD']:
              error = 'Invalid password'
          else:
              session['logged_in'] = True
              flash('You were logged in')
              return redirect(url_for('show_entries'))
      return render_template('login.html', error=error)
  
  
  @app.route('/logout')
  def logout():
      session.pop('logged_in', None)
      flash('You were logged out')
      return redirect(url_for('show_entries'))
  
  
  def allowed_file(filename):
      return '.' in filename and \
             filename.rsplit('.', 1)[1].lower() in ALLOWED_EXTENSIONS
  
  
  @app.route('/projects/<token>/images', methods=['GET', 'POST'])
  def upload_file(token):
      if request.method == 'POST':
          # check if the post request has the file part
          if 'file' not in request.files:
              flash('No file part')
              return redirect(request.url)
          file = request.files['file']
          # if user does not select file, browser also
          # submit a empty part without filename
          if file.filename == '':
              flash('No selected file')
              return redirect(request.url)
          if file and allowed_file(file.filename):
              filename = secure_filename(file.filename)
              file.save(os.path.join(app.config['UPLOAD_FOLDER'], filename))
              return redirect(url_for('uploaded_file',
                                      filename=filename))
      return '''
      <!doctype html>
      <title>Upload new File</title>
      <h1>Upload new File</h1>
      <form method=post enctype=multipart/form-data>
        <p><input type=file name=file>
           <input type=submit value=Upload>
      </form>
      '''
  
  
  @app.route('/uploads/<filename>')
  def uploaded_file(filename):
      return send_from_directory(app.config['UPLOAD_FOLDER'],
                                 filename)
  
  @app.before_first_request
  def startup():
      init_db()
  
  
  if __name__ == '__main__':
      app.run(debug=True)
  
  