im giving all the code for my chatbot app check why this error is occurring:
Internal Server Error
The server encountered an internal error and was unable to complete your request. Either the server is overloaded or there is an error in the application.

this is my code:
##index.html
<!DOCTYPE html>
<html>
  <head>
    <meta charset="UTF-8">
    <link rel="icon" href="{{ url_for('static', filename='images/icon.ico') }}">
    <title>MindMate - Mental health chatbot</title>
    <link rel="stylesheet" href="{{ url_for('static', filename='style.css') }}">
    <button id="logout-button" onclick="logout()"><span class="power">&#x23FB;</span>logout</button>
    <script>
    function logout() {
      window.location = "{{ url_for('logout') }}";
    }
    </script>
    <style>
      body {
        background-image: url("{{ url_for('static', filename='images/peakpx.jpg') }}");
        background-size: cover;
        background-position: center;
      }
      #logout-button {
          position: absolute;
          top: 10px;
          right: 10px;
      }
    </style>
  
  </head>

  <body id="body-area">
    <div id="chat-container">
      <div id="chat-header">
        <h1 id="logo"><img src="{{ url_for('static', filename='images/logo.ico')}}" alt="logo" >MindMate</h1>

      </div>
      <div id="chat-area"></div>
      <div id="input-container">
        <input type="text" id="user-input" placeholder="Type your message..." onkeydown="if(event.keyCode===13) sendMessage()">
        <button id="send-btn" onclick="sendMessage()" type="button">Send</button>
      </div>
    </div>
    <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js"></script>
    <script>
      function sendMessage() {
        var message = $("#user-input").val();
        $("#chat-area").append('<div class="user-msg"><span class="msg">' + message + '</span></div>');
        $.get("/get", {msg: message}).done(function(data) {
          $("#chat-area").append('<div class="bot-msg"><span class="msg">' + data + '</span></div>');
          $("#chat-area").scrollTop($("#chat-area")[0].scrollHeight);
        });
        $("#user-input").val("");
      }
    </script>
  </body>
</html>

##app.py
# Create flask app.py
from flask import Flask, render_template, url_for, redirect,request
import random
import json
import pickle
import numpy as np
import nltk
nltk.download('punkt')
nltk.download('wordnet')
from nltk.tokenize import word_tokenize
from nltk.stem import WordNetLemmatizer
import tensorflow as tf
from flask_sqlalchemy import SQLAlchemy
from flask_login import UserMixin, login_user, LoginManager, login_required, logout_user, current_user
from flask_wtf import FlaskForm
from wtforms import StringField, PasswordField, SubmitField
from wtforms.validators import InputRequired, Length, ValidationError
from flask_bcrypt import Bcrypt
from datetime import datetime
app = Flask(__name__, static_folder='static')
app.config['SQLALCHEMY_DATABASE_URI'] = 'sqlite:///database.db'
db = SQLAlchemy(app)
bcrypt = Bcrypt(app)
app.config['SECRET_KEY'] = 'thisisasecretkey'

login_manager = LoginManager()
login_manager.init_app(app)
login_manager.login_view = 'login'


@login_manager.user_loader
def load_user(user_id):
    return User.query.get(int(user_id))


class User(db.Model, UserMixin):
    id = db.Column(db.Integer, primary_key=True)
    username = db.Column(db.String(20), nullable=False, unique=True)
    password = db.Column(db.String(80), nullable=False)

class Chat(db.Model):
    id = db.Column(db.Integer, primary_key=True)
    user_id = db.Column(db.Integer, db.ForeignKey('user.id'), nullable=False)
    message = db.Column(db.String(255), nullable=False)
    response = db.Column(db.String(255), nullable=False)
    timestamp = db.Column(db.DateTime, nullable=False, default=datetime.utcnow)

class RegisterForm(FlaskForm):
    username = StringField(validators=[
                           InputRequired(), Length(min=4, max=20)], render_kw={"placeholder": "Username"})

    password = PasswordField(validators=[
                             InputRequired(), Length(min=8, max=20)], render_kw={"placeholder": "Password"})

    submit = SubmitField('Register')

    def validate_username(self, username):
        existing_user_username = User.query.filter_by(
            username=username.data).first()
        if existing_user_username:
            raise ValidationError(
                'That username already exists. Please choose a different one.')


class LoginForm(FlaskForm):
    username = StringField(validators=[
                           InputRequired(), Length(min=4, max=20)], render_kw={"placeholder": "Username"})

    password = PasswordField(validators=[
                             InputRequired(), Length(min=8, max=20)], render_kw={"placeholder": "Password"})

    submit = SubmitField('Login')


# Load the model, words, classes, and intents
model = tf.keras.models.load_model("E:\\Projects\\chatbot\\models\\new_chat_model.h5")
data = pickle.load(open("E:\\Projects\\chatbot\\models\\chat_data.pkl", "rb"))
words = data["words"]
classes = data["classes"]
intents = json.load(open("E:\Projects\chatbot\data\data.json",'r'))["intents"]

def bag_of_words(sentence):
    bag = [0] * len(words)
    lemmatizer = WordNetLemmatizer()
    sentence_words = word_tokenize(sentence)
    sentence_words = [lemmatizer.lemmatize(word.lower()) for word in sentence_words]

    for word in sentence_words:
        if word.lower() in words:
            bag[words.index(word.lower())] = 1

    return np.array(bag)

def chatbot_response(message):
    try:
        results = model.predict(np.array([bag_of_words(message)]))
        results_index = np.argmax(results)
        tag = classes[results_index]

        for intent in intents:
            if intent["tag"] == tag:
                response = random.choice(intent["responses"])
                return response
    except Exception as e:
        print("Error in chatbot_response:", e)
        return "I'm sorry, I couldn't understand that."


@app.route("/chatbot")
@login_required
def chatbot():
    # Retrieve chats associated with the current user
    chats = Chat.query.filter_by(user_id=current_user.id).all()

    # Create a list of dictionaries to hold chat messages and responses
    chat_history = []
    for chat in chats:
        chat_history.append({'message': chat.message, 'response': chat.response})

    return render_template("index.html", chat_history=chat_history)



@app.route("/get")
@login_required
def get_bot_response():
    try:
        msg = request.args.get('msg')
        response = chatbot_response(msg)
        chat = Chat(user_id=current_user.id, message=msg, response=response)
        db.session.add(chat)
        db.session.commit()
        return response
    except Exception as e:
        print("Error in get_bot_response:", e)
        return "An error occurred, please try again."

@app.route('/login', methods=['GET', 'POST'])
def login():
    form = LoginForm()
    if form.validate_on_submit():
        user = User.query.filter_by(username=form.username.data).first()
        if user:
            if bcrypt.check_password_hash(user.password, form.password.data):
                login_user(user)
                return redirect(url_for('chatbot'))
    return render_template('login.html', form=form)


@app.route('/logout', methods=['GET', 'POST'])
@login_required
def logout():
    logout_user()
    return redirect(url_for('login'))


@ app.route('/register', methods=['GET', 'POST'])
def register():
    form = RegisterForm()

    if form.validate_on_submit():
        hashed_password = bcrypt.generate_password_hash(form.password.data)
        new_user = User(username=form.username.data, password=hashed_password)
        db.session.add(new_user)
        db.session.commit()
        return redirect(url_for('login'))

    return render_template('register.html', form=form)


if __name__ == "__main__":
    app.run(debug=False)

##script.js

document.addEventListener("DOMContentLoaded", function(event) {
    // Selecting DOM elements
    const chatForm = document.getElementById("chat-form");
    const chatInput = document.getElementById("user-input");
    const chatbotMessages = document.getElementById("chatbot-messages");
    const sendBtn = document.getElementById("send-btn");
  
    //Event listener for the chat form submit
chatForm.addEventListener("submit", (event) => {
      event.preventDefault();
      const userInput = chatInput.value;
      addUserMessage(userInput);
      sendUserMessage(userInput);
      chatInput.value = "";
      scrollToBottom();
    });
  
    //Event listener for the send button click
sendBtn.addEventListener("click", () => {
      const userInput = chatInput.value;
      addUserMessage(userInput);
      sendUserMessage(userInput);
      chatInput.value = "";
      scrollToBottom();
    });
  
    // Function to add a user message to the chat area
function addUserMessage(message) {
      const userMessageElement = `
        <div class="user-message">
          <p>${message}</p>
        </div>
      `;
      chatbotMessages.insertAdjacentHTML("beforeend", userMessageElement);
      scrollToBottom();
    }
  
    // Function to send user message to server and get response
function sendUserMessage(message) {
      showChatbotLoader();
      fetch("/get-response", {
        method: "POST",
        headers: {
          "Content-Type": "application/json",
        },
        body: JSON.stringify({ message }),
      })
        .then((response) => response.json())
        .then((data) => {
          const chatbotMessage = data.message;
          addChatbotMessage(chatbotMessage);
          hideChatbotLoader();
          scrollToBottom();
        })
        .catch((error) => {
          console.log("Error:", error);
          hideChatbotLoader();
        });
    }
  
    // Function to add a chatbot message to the chat area
function addChatbotMessage(message) {
      const chatbotMessageElement = `
        <div id="chatbot-message" class="chat-message">
          <p>${message}</p>
        </div>
      `;
      chatbotMessages.insertAdjacentHTML(
        "beforeend",
        chatbotMessageElement
      );
      scrollToBottom();
    }
  // Function to scroll to the bottom of the chat container

function scrollToBottom() {
    const scrollContainer = document.getElementById('chat-area');
    scrollContainer.scrollTop = scrollContainer.scrollHeight;
  }
  
  
    // Function to hide the chatbot loader
function hideChatbotLoader() {
      const loaderElement = document.querySelector(".loader");
      if (loaderElement) {
        loaderElement.remove();
      }
    }
  
    // Add an event listener to the input field
    chatInput.addEventListener("keydown", function(event) {
      // Check if the key pressed is the enter key (key code 13)
      if (event.key === 'Enter') {
        // Prevent the default behavior of the enter key (submitting the form)
        event.preventDefault();

        // Trigger the click event on the send button
        document.getElementById("send-btn").click();
        scrollToBottom();
      }
    }); 

});

##login.html
<!DOCTYPE html>
<html>

<head>
    <meta charset="UTF-8">
    <link rel="icon" href="{{ url_for('static', filename='images/icon.ico') }}">
    <title>Login Page</title>
    <style>
        body {
            
            background-image: url("{{ url_for('static', filename='images/peakpx.jpg') }}");
            font-family: Arial, Helvetica, sans-serif;
            font-size: 16px;
            color: #333;
        }

        h1 {
            font-size: 36px;
            text-align: center;
            margin-top: 50px;
            margin-bottom: 30px;
            color: whitesmoke;
        }

        form {
            width: 400px;
            margin: 0 auto;
        }

        label {
            display: block;
            margin-bottom: 10px;
            font-weight: bold;
            color:white;
        }

        input[type="text"],
        input[type="password"] {
            width: 100%;
            padding: 10px;
            margin-bottom: 20px;
            border-radius: 5px;
            background-color: grey;
            border: 1px solid #ccc;
            box-sizing: border-box;
        }

        button[type="submit"] {
            display: block;
            width: 100%;
            padding: 10px;
            background-color: blue;
            color: white;
            border: none;
            border-radius: 5px;
            cursor: pointer;
        }

        a {
            display: block;
            text-align: center;
            margin-top: 20px;
            color: white;
        }
    </style>
</head>

<body>
    <h1>Login Page</h1>

    <form method="POST" action="">
        {{ form.hidden_tag() }}
        <label for="username">Username</label>
        <input type="text" name="username" id="username">
        <label for="password">Password</label>
        <input type="password" name="password" id="password">
        <button type="submit">Login</button>
    </form>

    <a href="{{ url_for('register') }}">Don't have an account? Sign Up</a>
</body>

</html>

##register.html
<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Register</title>
</head>

<body>
    <h1>Register Page</h1>

    <form method="POST" action="">
        {{ form.hidden_tag() }}
        {{ form.username }}
        {{ form.password }}
        {{ form.submit }}
    </form>

    <a href="{{ url_for('login') }}">Already have an account? Log In</a>
</body>

</html>

##in sqlite3 database.db
sqlite> CREATE TABLE user (
   ...>     id INTEGER PRIMARY KEY AUTOINCREMENT,
   ...>     email VARCHAR(50) NOT NULL UNIQUE,
   ...>     password VARCHAR(255) NOT NULL
   ...> );
sqlite>
sqlite> CREATE TABLE chat (
   ...>     id INTEGER PRIMARY KEY AUTOINCREMENT,
   ...>     user_id INTEGER NOT NULL,
   ...>     message TEXT NOT NULL,
   ...>     response TEXT NOT NULL,
   ...>     timestamp DATETIME DEFAULT CURRENT_TIMESTAMP,
   ...>     FOREIGN KEY (user_id) REFERENCES user(id)
   ...> );
sqlite> .tables
chat  user