code: from flask_restx import Resource
  from flask import request, render_template, Response
  import openai
  import os
  import json
  from llama_index import GPTSimpleVectorIndex
  from llama_index import Document
  from furl import furl
  from PyPDF2 import PdfReader
  
  os.environ["OPENAI_API_KEY"] = "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"
  openai.organization = "org-Ddi6ZSgWKe8kPZlpwd6M6WVe"
  openai.api_key = os.getenv("OPENAI_API_KEY")
  
  
  def get_domain(link):
      print("link", link)
      f = furl(link)
      host = f.host
      tld = host.split(".")
      if len(tld) > 2:
          return tld[1]
      else:
          return tld[0]
  
  
  def get_title(title):
      f = furl(title)
      host = f.host
      if host != "":
          return host
      else:
          return title
  
  
  class Upload(Resource):
      def post(self):
          data = {}
          userid = data.get('userid', 'cibi')
          print(request.files)
          file = request.files['userfile']
          file.save(userid + file.filename)
          print(file)
          reader = PdfReader(userid + file.filename)
          data = ""
          for page in reader.pages:
              data += page.extract_text()
          unique_doc = file.filename
          file_name = str(hash(userid + unique_doc)) + ".txt"
          #dict_obj = {"userid":userid,"pageTitle":pageTitle}
          alreadyPresentList = []
          userDataJson = {}
          if os.path.exists("./userData.json"):
              with open('./userData.json', 'r') as userDataJsonFile:
                  userDataJson = json.loads(userDataJsonFile.read())
                  if userid in userDataJson:
                      alreadyPresentList = userDataJson[userid]
                      if unique_doc not in alreadyPresentList:
                          alreadyPresentList.append(unique_doc)
          else:
              alreadyPresentList.append(unique_doc)
          userDataJson[userid] = alreadyPresentList
          print("New data : ", str(userDataJson))
          userDataJsonFileWrite = open('./userData.json', "w")
          userDataJsonFileWrite.write(json.dumps(userDataJson))
          userDataJsonFileWrite.close()
          with open(str(file_name), 'w') as fl:
              fl.write(data)
          llama_doc = Document(data, doc_id=userid + "<sep>" + unique_doc)
          if os.path.exists("database.json"):
              existing_index = GPTSimpleVectorIndex.load_from_disk('database.json')
              existing_index.update(llama_doc)
              existing_index.save_to_disk("database.json")
          else:
              index = GPTSimpleVectorIndex.from_documents(documents=[llama_doc])
              index.update(llama_doc)
              index.save_to_disk("database.json")
          response = ""
          return response, 200
apis: llama_index.GPTSimpleVectorIndex.from_documents llama_index.GPTSimpleVectorIndex.load_from_disk llama_index.Document
extract_api: [((407, 434), 'os.getenv', 'os.getenv', (['"""OPENAI_API_KEY"""'], {}), "('OPENAI_API_KEY')\n", (416, 434), False, 'import os\n'), ((491, 501), 'furl.furl', 'furl', (['link'], {}), '(link)\n', (495, 501), False, 'from furl import furl\n'), ((653, 664), 'furl.furl', 'furl', (['title'], {}), '(title)\n', (657, 664), False, 'from furl import furl\n'), ((1010, 1043), 'PyPDF2.PdfReader', 'PdfReader', (['(userid + file.filename)'], {}), '(userid + file.filename)\n', (1019, 1043), False, 'from PyPDF2 import PdfReader\n'), ((1360, 1393), 'os.path.exists', 'os.path.exists', (['"""./userData.json"""'], {}), "('./userData.json')\n", (1374, 1393), False, 'import os\n'), ((2173, 2225), 'llama_index.Document', 'Document', (['data'], {'doc_id': "(userid + '<sep>' + unique_doc)"}), "(data, doc_id=userid + '<sep>' + unique_doc)\n", (2181, 2225), False, 'from llama_index import Document\n'), ((2237, 2268), 'os.path.exists', 'os.path.exists', (['"""database.json"""'], {}), "('database.json')\n", (2251, 2268), False, 'import os\n'), ((2016, 2040), 'json.dumps', 'json.dumps', (['userDataJson'], {}), '(userDataJson)\n', (2026, 2040), False, 'import json\n'), ((2299, 2351), 'llama_index.GPTSimpleVectorIndex.load_from_disk', 'GPTSimpleVectorIndex.load_from_disk', (['"""database.json"""'], {}), "('database.json')\n", (2334, 2351), False, 'from llama_index import GPTSimpleVectorIndex\n'), ((2488, 2546), 'llama_index.GPTSimpleVectorIndex.from_documents', 'GPTSimpleVectorIndex.from_documents', ([], {'documents': '[llama_doc]'}), '(documents=[llama_doc])\n', (2523, 2546), False, 'from llama_index import GPTSimpleVectorIndex\n')]