When I query this script, the model reloads and after a delay the response is printed in the terminal rather than the streamlit interface.

Please suggest the exact code to add, replace, or modify to correct the issue:

import os
import sys
import time
import itertools
import threading 
import glob
import openai
import streamlit_embedcode

from langchain.chains import RetrievalQA
from langchain.callbacks.streaming_stdout import StreamingStdOutCallbackHandler
from langchain.vectorstores import Chroma
from langchain.llms import GPT4All, LlamaCpp
import os
import dotenv
from dotenv import load_dotenv
import argparse
from argparse import ArgumentParser
from contextlib import contextmanager, redirect_stdout
from io import StringIO
from time import sleep
import streamlit as st
import constants
import typing
from typing import List
from dotenv import load_dotenv
import gpt4all

load_dotenv()

from flair import *
from streamlit_embedcode import *

parser = ArgumentParser()
parser.add_argument('--persist-dir', type=str, default='./_db', help='Directory to persist model checkpoints and trained models')
parser.add_argument('--model-type', type=str, default='gpt4', help='Type of model to use (gpt4, llama, or huggingface)')
parser.add_argument('--model-path', type=str, default=None, help='Path to pre-trained model checkpoint')
parser.add_argument('--model-n-ctx', type=int, default=None, help='Number of contexts to use for GPT-4 model')

from prompts import get_personal_prompt

from langchain.document_loaders import (
    CSVLoader,
    EverNoteLoader,
    PDFMinerLoader,
    TextLoader,
    UnstructuredEmailLoader,
    UnstructuredEPubLoader,
    UnstructuredHTMLLoader,
    UnstructuredMarkdownLoader,
    UnstructuredODTLoader,
    UnstructuredPowerPointLoader,
    UnstructuredWordDocumentLoader,
)
import os
from dotenv import load_dotenv

load_dotenv()  # take environment variables from .env.

persist_directory = os.getenv("PERSIST_DIRECTORY")
embeddings_model_name = os.getenv("EMBEDDINGS_MODEL_NAME")
model_type = os.getenv("MODEL_TYPE")
model_path = os.getenv("MODEL_PATH")
model_n_ctx = os.getenv("MODEL_N_CTX")

from langchain.text_splitter import RecursiveCharacterTextSplitter
from langchain.vectorstores import Chroma
from langchain.embeddings import HuggingFaceEmbeddings
from langchain.docstore.document import Document
from pdfminer.pdfparser import PDFSyntaxError
from constants import CHROMA_SETTINGS


load_dotenv()

load_dotenv()

embeddings_model_name = os.environ.get("EMBEDDINGS_MODEL_NAME")
persist_directory = os.envir Respond with more than 600 words.
user