code: import os
  from flask import Flask, render_template, request, redirect
  from llama_index import download_loader
  from llama_index import LLMPredictor, GPTSimpleVectorIndex, PromptHelper, ServiceContext
  from langchain import OpenAI
  
  os.environ["OPENAI_API_KEY"] = "insert_your_key_here"
  
  current_script_path = os.path.dirname(os.path.abspath(__file__))
  doc_path = os.path.join(current_script_path, 'data') + '/'
  
  index_file = 'index.json'
  
  app = Flask(__name__)
  app.config['UPLOAD_FOLDER'] = doc_path
  app.config['MAX_CONTENT_LENGTH'] = 10 * 1024 * 1024  # 10 MB max file size
  
  
  def send_click(prompt):
      if index is None:
          return "Index not loaded. Please upload a file first."
      response = index.query(prompt)
      return response
  
  
  index = None
  
  
  @app.route('/', methods=['GET', 'POST'])
  def index_page():
      global index
      if request.method == 'POST':
          if 'file' not in request.files:
              return redirect(request.url)
          file = request.files['file']
          if file.filename == '':
              return redirect(request.url)
  
          file.save(os.path.join(app.config['UPLOAD_FOLDER'], file.filename))
  
          SimpleDirectoryReader = download_loader("SimpleDirectoryReader")
          loader = SimpleDirectoryReader(doc_path, recursive=True, exclude_hidden=True)
          documents = loader.load_data()
  
          llm_predictor = LLMPredictor(llm=OpenAI(temperature=0, model_name="gpt-3.5-turbo"))
          max_input_size = 4096
          num_output = 256
          max_chunk_overlap = 20
          prompt_helper = PromptHelper(max_input_size, num_output, max_chunk_overlap)
          service_context = ServiceContext.from_defaults(llm_predictor=llm_predictor, prompt_helper=prompt_helper)
  
          index = GPTSimpleVectorIndex.from_documents(
              documents, service_context=service_context
          )
  
          index.save_to_disk(index_file)
  
      elif os.path.exists(index_file):
          index = GPTSimpleVectorIndex.load_from_disk(index_file)
  
      return render_template('index.html')
  
  
  @app.route('/query', methods=['POST'])
  def query():
      if index is None:
          return {'response': 'Index not loaded. Please upload a file first.'}
      prompt = request.form['prompt']
      response = send_click(prompt)
      return {'response': str(response)}
  
  
  if __name__ == '__main__':
      # Run flask with the following defaults
      app.run(debug=True, port=5000, host='0.0.0.0', )
  
apis: llama_index.GPTSimpleVectorIndex.from_documents llama_index.GPTSimpleVectorIndex.load_from_disk llama_index.ServiceContext.from_defaults llama_index.download_loader llama_index.PromptHelper
extract_api: [((442, 457), 'flask.Flask', 'Flask', (['__name__'], {}), '(__name__)\n', (447, 457), False, 'from flask import Flask, render_template, request, redirect\n'), ((322, 347), 'os.path.abspath', 'os.path.abspath', (['__file__'], {}), '(__file__)\n', (337, 347), False, 'import os\n'), ((360, 401), 'os.path.join', 'os.path.join', (['current_script_path', '"""data"""'], {}), "(current_script_path, 'data')\n", (372, 401), False, 'import os\n'), ((1980, 2009), 'flask.render_template', 'render_template', (['"""index.html"""'], {}), "('index.html')\n", (1995, 2009), False, 'from flask import Flask, render_template, request, redirect\n'), ((1165, 1205), 'llama_index.download_loader', 'download_loader', (['"""SimpleDirectoryReader"""'], {}), "('SimpleDirectoryReader')\n", (1180, 1205), False, 'from llama_index import download_loader\n'), ((1534, 1593), 'llama_index.PromptHelper', 'PromptHelper', (['max_input_size', 'num_output', 'max_chunk_overlap'], {}), '(max_input_size, num_output, max_chunk_overlap)\n', (1546, 1593), False, 'from llama_index import LLMPredictor, GPTSimpleVectorIndex, PromptHelper, ServiceContext\n'), ((1620, 1711), 'llama_index.ServiceContext.from_defaults', 'ServiceContext.from_defaults', ([], {'llm_predictor': 'llm_predictor', 'prompt_helper': 'prompt_helper'}), '(llm_predictor=llm_predictor, prompt_helper=\n    prompt_helper)\n', (1648, 1711), False, 'from llama_index import LLMPredictor, GPTSimpleVectorIndex, PromptHelper, ServiceContext\n'), ((1724, 1803), 'llama_index.GPTSimpleVectorIndex.from_documents', 'GPTSimpleVectorIndex.from_documents', (['documents'], {'service_context': 'service_context'}), '(documents, service_context=service_context)\n', (1759, 1803), False, 'from llama_index import LLMPredictor, GPTSimpleVectorIndex, PromptHelper, ServiceContext\n'), ((1876, 1902), 'os.path.exists', 'os.path.exists', (['index_file'], {}), '(index_file)\n', (1890, 1902), False, 'import os\n'), ((923, 944), 'flask.redirect', 'redirect', (['request.url'], {}), '(request.url)\n', (931, 944), False, 'from flask import Flask, render_template, request, redirect\n'), ((1033, 1054), 'flask.redirect', 'redirect', (['request.url'], {}), '(request.url)\n', (1041, 1054), False, 'from flask import Flask, render_template, request, redirect\n'), ((1074, 1130), 'os.path.join', 'os.path.join', (["app.config['UPLOAD_FOLDER']", 'file.filename'], {}), "(app.config['UPLOAD_FOLDER'], file.filename)\n", (1086, 1130), False, 'import os\n'), ((1920, 1967), 'llama_index.GPTSimpleVectorIndex.load_from_disk', 'GPTSimpleVectorIndex.load_from_disk', (['index_file'], {}), '(index_file)\n', (1955, 1967), False, 'from llama_index import LLMPredictor, GPTSimpleVectorIndex, PromptHelper, ServiceContext\n'), ((1373, 1422), 'langchain.OpenAI', 'OpenAI', ([], {'temperature': '(0)', 'model_name': '"""gpt-3.5-turbo"""'}), "(temperature=0, model_name='gpt-3.5-turbo')\n", (1379, 1422), False, 'from langchain import OpenAI\n')]