code: import os
  import datetime
  import sys
  import json
  import time
  import os
  
  from langchain.embeddings import OpenAIEmbeddings
  from langchain.vectorstores import LanceDB
  from langchain.document_loaders import DirectoryLoader
  from langchain.text_splitter import CharacterTextSplitter
  import lancedb
  import openai
  
  from flask import Flask, render_template, request, jsonify
  from langchain.text_splitter import RecursiveCharacterTextSplitter
  from werkzeug.utils import secure_filename
  from deep_motion import DeepMotionHandler
  from sketchfab import SketchfabHandler
  
  
  
  os.environ["OPENAI_API_KEY"] = "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"
  openai.api_key = "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"
  
  
  
  
  loader = DirectoryLoader("static/langchain_documents/")
  
  loaded_documents = loader.load()
  text_splitter = CharacterTextSplitter(chunk_size=300, chunk_overlap=100)
  documents = text_splitter.split_documents(loaded_documents)
  #documents = TextSplitter().split_documents(documents)
  print(type(documents))
  embeddings = OpenAIEmbeddings()
  
  db = lancedb.connect("static/lanceDB")
  table = db.open_table("my_table")
  #
  # table = db.create_table(
  #     "my_table",
  #     data=[
  #         {
  #             "vector": embeddings.embed_query("Hello World"),
  #             "text": "Hello World",
  #             "id": "1",
  #         }
  #     ],
  #     mode="overwrite",
  #
  # )
  
  docsearch = LanceDB.from_documents(documents, embeddings, connection=table)
  
  UPLOAD_FOLDER = '/uploaded_videos'
  ALLOWED_EXTENSIONS = {'mp4', 'mov'}
  
  app = Flask(__name__)
  app.config['UPLOAD_FOLDER'] = UPLOAD_FOLDER
  
  current_convert_config = {"trainee_url": "", "coach_url": ""}
  
  @app.route("/")
  def home():
      return render_template("home.html")
  
  @app.route("/shottracer")
  def shottracer():
      print("here", flush=True)
      return render_template("shottracer.html")
  
  @app.route("/about")
  def about():
      return render_template("about.html")
  
  @app.route("/upload", methods=["POST"])
  def upload():
      print("Entered upload", flush=True)
      try:
          uploaded_file = request.files['file']
          if uploaded_file and uploaded_file.filename.endswith('.mp4'):
              print("uploaded file and is mp4", flush=True)
              uploaded_file.save('uploaded_video.mp4')
              return {'message': 'Video uploaded and saved successfully'}
          else:
              print("failed lmao", flush=True)
              return {'message': 'Invalid video file'}
      except Exception as e:
          return {'message': 'Error uploading video: ' + str(e)}
  
  @app.route('/process', methods=['POST'])
  def process():
      print("in process", flush=True)
      print(request.data, flush=True)
      data = json.loads(request.data)
  
      result = data['value']
      
  
      current_convert_config["trainee_url"] = "static/videos/" + result
  
      print("selected trainee: " + current_convert_config["trainee_url"], flush=True)
  
      return jsonify(result=result)
  
  @app.route('/coach_select', methods=["POST"])
  def coach_select():
  
      data = json.loads(request.data)
      result = data['value']
  
  
      current_convert_config["coach_url"] = "static/videos/" + result
      print("selected coach: " + current_convert_config["coach_url"], flush=True)
  
      return jsonify(result=result)
  
  @app.route('/convert', methods=["POST"])
  def convert():
      print("converting", flush=True)
      if current_convert_config["trainee_url"] == "" or current_convert_config["coach_url"] == "":
          print(current_convert_config)
          return current_convert_config
  
      deep_motion = DeepMotionHandler()
  
      trainee_resp, trainee_input = deep_motion.new_job(current_convert_config["trainee_url"], download=False)
      coach_resp, coach_input = deep_motion.new_job(current_convert_config["coach_url"], download=False)
  
      trainee_fbx = deep_motion.download_job(trainee_resp, trainee_input)
      coach_fbx = deep_motion.download_job(coach_resp, coach_input)
  
      print(trainee_fbx, flush=True)
      print(coach_fbx, flush=True)
  
      sketchfab_handler = SketchfabHandler()
      trainee_url = sketchfab_handler.upload(trainee_fbx)
      coach_url = sketchfab_handler.upload(coach_fbx)
  
      print(trainee_url, flush=True)
      print(coach_url, flush=True)
  
      while not sketchfab_handler.poll_processing_status(trainee_url) or not sketchfab_handler.poll_processing_status(coach_url):
          time.sleep(1)
  
      return jsonify('{"trainee": "' + trainee_url.rsplit('/', 1)[-1] + '", "coach": "' + coach_url.rsplit('/', 1)[-1] + '"}')
      #return jsonify('{"trainee": "791e22a2678e4e05b56df1107dd1f8e8", "coach": "af8a9327edf3432f981000210da42022"}')
      #return (trainee_url.rsplit('/', 1)[-1], coach_url.rsplit('/', 1)[-1])
  
  
  @app.route("/search", methods=["POST"])
  def docSearch():
      print("in search", flush=True)
      print(request.data, flush=True)
      data = json.loads(request.data)
      question = data['question']
      docs = docsearch.similarity_search(question)
  
      prompt = f"""Given the question: {question} and this context: {docs}
      Answer the question as best as possible. Use any relevant information from the context to
      enrich your answer.
      Final Answer:
      """
  
      response = openai.Completion.create(
          engine="text-davinci-003",
          prompt=prompt,
          max_tokens=300
      )
  
      generated_text = response.choices[0].text
  
      return jsonify(result=generated_text)
  
  if __name__ == "__main__":
      app.run(host="127.0.0.1", port=8080, debug=True)
apis: lancedb.connect
extract_api: [((730, 776), 'langchain.document_loaders.DirectoryLoader', 'DirectoryLoader', (['"""static/langchain_documents/"""'], {}), "('static/langchain_documents/')\n", (745, 776), False, 'from langchain.document_loaders import DirectoryLoader\n'), ((827, 883), 'langchain.text_splitter.CharacterTextSplitter', 'CharacterTextSplitter', ([], {'chunk_size': '(300)', 'chunk_overlap': '(100)'}), '(chunk_size=300, chunk_overlap=100)\n', (848, 883), False, 'from langchain.text_splitter import CharacterTextSplitter\n'), ((1035, 1053), 'langchain.embeddings.OpenAIEmbeddings', 'OpenAIEmbeddings', ([], {}), '()\n', (1051, 1053), False, 'from langchain.embeddings import OpenAIEmbeddings\n'), ((1060, 1093), 'lancedb.connect', 'lancedb.connect', (['"""static/lanceDB"""'], {}), "('static/lanceDB')\n", (1075, 1093), False, 'import lancedb\n'), ((1389, 1452), 'langchain.vectorstores.LanceDB.from_documents', 'LanceDB.from_documents', (['documents', 'embeddings'], {'connection': 'table'}), '(documents, embeddings, connection=table)\n', (1411, 1452), False, 'from langchain.vectorstores import LanceDB\n'), ((1532, 1547), 'flask.Flask', 'Flask', (['__name__'], {}), '(__name__)\n', (1537, 1547), False, 'from flask import Flask, render_template, request, jsonify\n'), ((1695, 1723), 'flask.render_template', 'render_template', (['"""home.html"""'], {}), "('home.html')\n", (1710, 1723), False, 'from flask import Flask, render_template, request, jsonify\n'), ((1810, 1844), 'flask.render_template', 'render_template', (['"""shottracer.html"""'], {}), "('shottracer.html')\n", (1825, 1844), False, 'from flask import Flask, render_template, request, jsonify\n'), ((1891, 1920), 'flask.render_template', 'render_template', (['"""about.html"""'], {}), "('about.html')\n", (1906, 1920), False, 'from flask import Flask, render_template, request, jsonify\n'), ((2666, 2690), 'json.loads', 'json.loads', (['request.data'], {}), '(request.data)\n', (2676, 2690), False, 'import json\n'), ((2892, 2914), 'flask.jsonify', 'jsonify', ([], {'result': 'result'}), '(result=result)\n', (2899, 2914), False, 'from flask import Flask, render_template, request, jsonify\n'), ((2994, 3018), 'json.loads', 'json.loads', (['request.data'], {}), '(request.data)\n', (3004, 3018), False, 'import json\n'), ((3208, 3230), 'flask.jsonify', 'jsonify', ([], {'result': 'result'}), '(result=result)\n', (3215, 3230), False, 'from flask import Flask, render_template, request, jsonify\n'), ((3516, 3535), 'deep_motion.DeepMotionHandler', 'DeepMotionHandler', ([], {}), '()\n', (3533, 3535), False, 'from deep_motion import DeepMotionHandler\n'), ((3982, 4000), 'sketchfab.SketchfabHandler', 'SketchfabHandler', ([], {}), '()\n', (3998, 4000), False, 'from sketchfab import SketchfabHandler\n'), ((4787, 4811), 'json.loads', 'json.loads', (['request.data'], {}), '(request.data)\n', (4797, 4811), False, 'import json\n'), ((5127, 5213), 'openai.Completion.create', 'openai.Completion.create', ([], {'engine': '"""text-davinci-003"""', 'prompt': 'prompt', 'max_tokens': '(300)'}), "(engine='text-davinci-003', prompt=prompt,\n    max_tokens=300)\n", (5151, 5213), False, 'import openai\n'), ((5299, 5329), 'flask.jsonify', 'jsonify', ([], {'result': 'generated_text'}), '(result=generated_text)\n', (5306, 5329), False, 'from flask import Flask, render_template, request, jsonify\n'), ((4315, 4328), 'time.sleep', 'time.sleep', (['(1)'], {}), '(1)\n', (4325, 4328), False, 'import time\n')]