im getting this error: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 errors occurs after login when index.html opens so tell me the possible error and give a modified code
# 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):
    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


@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)


@login_required
@app.route("/get")
def get_bot_response():
    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

@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)

##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>