code: def show_doc(
      db1s,
      selection_docs_state1,
      requests_state1,
      langchain_mode1,
      single_document_choice1,
      view_raw_text_checkbox1,
      text_context_list1,
      pdf_height,
      dbs1=None,
      load_db_if_exists1=None,
      db_type1=None,
      use_openai_embedding1=None,
      hf_embedding_model1=None,
      migrate_embedding_model_or_db1=None,
      auto_migrate_db1=None,
      verbose1=False,
      get_userid_auth1=None,
      max_raw_chunks=1000000,
      api=False,
      n_jobs=-1,
  ):
      file = single_document_choice1
      document_choice1 = [single_document_choice1]
      content = None
      db_documents = []
      db_metadatas = []
      if db_type1 in ["chroma", "chroma_old"]:
          assert langchain_mode1 is not None
          langchain_mode_paths = selection_docs_state1[
              "langchain_mode_paths"
          ]
          langchain_mode_types = selection_docs_state1[
              "langchain_mode_types"
          ]
          from src.gpt_langchain import (
              set_userid,
              get_any_db,
              get_docs_and_meta,
          )
  
          set_userid(db1s, requests_state1, get_userid_auth1)
          top_k_docs = -1
          db = get_any_db(
              db1s,
              langchain_mode1,
              langchain_mode_paths,
              langchain_mode_types,
              dbs=dbs1,
              load_db_if_exists=load_db_if_exists1,
              db_type=db_type1,
              use_openai_embedding=use_openai_embedding1,
              hf_embedding_model=hf_embedding_model1,
              migrate_embedding_model=migrate_embedding_model_or_db1,
              auto_migrate_db=auto_migrate_db1,
              for_sources_list=True,
              verbose=verbose1,
              n_jobs=n_jobs,
          )
          query_action = (
              False  # long chunks like would be used for summarize
          )
          # the below is as or filter, so will show doc or by chunk, unrestricted
          from langchain.vectorstores import Chroma
  
          if isinstance(db, Chroma):
              # chroma >= 0.4
              if view_raw_text_checkbox1:
                  one_filter = [
                      {"source": {"$eq": x}, "chunk_id": {"$gte": 0}}
                      if query_action
                      else {
                          "source": {"$eq": x},
                          "chunk_id": {"$gte": -1},
                      }
                      for x in document_choice1
                  ][0]
              else:
                  one_filter = [
                      {"source": {"$eq": x}, "chunk_id": {"$gte": 0}}
                      if query_action
                      else {
                          "source": {"$eq": x},
                          "chunk_id": {"$eq": -1},
                      }
                      for x in document_choice1
                  ][0]
              filter_kwargs = dict(
                  filter={
                      "$and": [
                          dict(source=one_filter["source"]),
                          dict(chunk_id=one_filter["chunk_id"]),
                      ]
                  }
              )
          else:
              # migration for chroma < 0.4
              one_filter = [
                  {"source": {"$eq": x}, "chunk_id": {"$gte": 0}}
                  if query_action
                  else {"source": {"$eq": x}, "chunk_id": {"$eq": -1}}
                  for x in document_choice1
              ][0]
              if view_raw_text_checkbox1:
                  # like or, full raw all chunk types
                  filter_kwargs = dict(filter=one_filter)
              else:
                  filter_kwargs = dict(
                      filter={
                          "$and": [
                              dict(source=one_filter["source"]),
                              dict(chunk_id=one_filter["chunk_id"]),
                          ]
                      }
                  )
          db_documents, db_metadatas = get_docs_and_meta(
              db,
              top_k_docs,
              filter_kwargs=filter_kwargs,
              text_context_list=text_context_list1,
          )
          # order documents
          from langchain.docstore.document import Document
  
          docs_with_score = [
              (
                  Document(
                      page_content=result[0], metadata=result[1] or {}
                  ),
                  0,
              )
              for result in zip(db_documents, db_metadatas)
          ]
          doc_chunk_ids = [x.get("chunk_id", -1) for x in db_metadatas]
          doc_page_ids = [x.get("page", 0) for x in db_metadatas]
          doc_hashes = [x.get("doc_hash", "None") for x in db_metadatas]
          docs_with_score = [
              x
              for hx, px, cx, x in sorted(
                  zip(
                      doc_hashes,
                      doc_page_ids,
                      doc_chunk_ids,
                      docs_with_score,
                  ),
                  key=lambda x: (x[0], x[1], x[2]),
              )
              # if cx == -1
          ]
          db_metadatas = [x[0].metadata for x in docs_with_score][
              :max_raw_chunks
          ]
          db_documents = [x[0].page_content for x in docs_with_score][
              :max_raw_chunks
          ]
          # done reordering
          if view_raw_text_checkbox1:
              content = [
                  dict_to_html(x) + "\n" + text_to_html(y)
                  for x, y in zip(db_metadatas, db_documents)
              ]
          else:
              content = [
                  text_to_html(y)
                  for x, y in zip(db_metadatas, db_documents)
              ]
          content = "\n".join(content)
          content = f"""<!DOCTYPE html>
  <html>
  <head>
  <title>{file}</title>
  </head>
  <body>
  {content}
  </body>
  </html>"""
      if api:
          if view_raw_text_checkbox1:
              return dict(contents=db_documents, metadatas=db_metadatas)
          else:
              contents = [
                  text_to_html(y, api=api) for y in db_documents
              ]
              metadatas = [
                  dict_to_html(x, api=api) for x in db_metadatas
              ]
              return dict(contents=contents, metadatas=metadatas)
      else:
          assert (
              not api
          ), "API mode for get_document only supported for chroma"
  
      dummy1 = gr.update(visible=False, value=None)
      # backup is text dump of db version
      if content:
          dummy_ret = (
              dummy1,
              dummy1,
              dummy1,
              dummy1,
              gr.update(visible=True, value=content),
              dummy1,
              dummy1,
              dummy1,
          )
          if view_raw_text_checkbox1:
              return dummy_ret
      else:
          dummy_ret = (
              dummy1,
              dummy1,
              dummy1,
              dummy1,
              dummy1,
              dummy1,
              dummy1,
              dummy1,
          )
  
      if not isinstance(file, str):
          return dummy_ret
  
      if (
          file.lower().endswith(".html")
          or file.lower().endswith(".mhtml")
          or file.lower().endswith(".htm")
          or file.lower().endswith(".xml")
      ):
          try:
              with open(file, "rt") as f:
                  content = f.read()
              return (
                  gr.update(visible=True, value=content),
                  dummy1,
                  dummy1,
                  dummy1,
                  dummy1,
                  dummy1,
                  dummy1,
                  dummy1,
              )
          except:
              return dummy_ret
  
      if file.lower().endswith(".md"):
          try:
              with open(file, "rt") as f:
                  content = f.read()
              return (
                  dummy1,
                  dummy1,
                  dummy1,
                  gr.update(visible=True, value=content),
                  dummy1,
                  dummy1,
                  dummy1,
                  dummy1,
              )
          except:
              return dummy_ret
  
      if file.lower().endswith(".py"):
          try:
              with open(file, "rt") as f:
                  content = f.read()
              content = f"```python\n{content}\n```"
              return (
                  dummy1,
                  dummy1,
                  dummy1,
                  gr.update(visible=True, value=content),
                  dummy1,
                  dummy1,
                  dummy1,
                  dummy1,
              )
          except:
              return dummy_ret
  
      if (
          file.lower().endswith(".txt")
          or file.lower().endswith(".rst")
          or file.lower().endswith(".rtf")
          or file.lower().endswith(".toml")
      ):
          try:
              with open(file, "rt") as f:
                  content = f.read()
              content = f"```text\n{content}\n```"
              return (
                  dummy1,
                  dummy1,
                  dummy1,
                  gr.update(visible=True, value=content),
                  dummy1,
                  dummy1,
                  dummy1,
                  dummy1,
              )
          except:
              return dummy_ret
  
      func = None
      if file.lower().endswith(".csv"):
          func = pd.read_csv
      elif file.lower().endswith(".pickle"):
          func = pd.read_pickle
      elif file.lower().endswith(".xls") or file.lower().endswith(
          "xlsx"
      ):
          func = pd.read_excel
      elif file.lower().endswith(".json"):
          func = pd.read_json
      # pandas doesn't show full thing, even if html view shows broken things still better
      # elif file.lower().endswith('.xml'):
      #    func = pd.read_xml
      if func is not None:
          try:
              df = func(file).head(100)
          except:
              # actual JSON required
              with open(file, "rt") as f:
                  json_blob = f.read()
              return (
                  dummy1,
                  dummy1,
                  gr.update(visible=True, value=json_blob),
                  dummy1,
                  dummy1,
                  dummy1,
                  dummy1,
                  dummy1,
              )
          return (
              dummy1,
              gr.update(visible=True, value=df),
              dummy1,
              dummy1,
              dummy1,
              dummy1,
              dummy1,
              dummy1,
          )
      port = int(os.getenv("GRADIO_SERVER_PORT", "7860"))
      import pathlib
  
      absolute_path_string = os.path.abspath(file)
      url_path = pathlib.Path(absolute_path_string).as_uri()
      url = get_url(absolute_path_string, from_str=True)
      img_url = url.replace("""<a href=""", """<img src=""")
      from src.gpt_langchain import (
          image_types,
          audio_types,
          video_types,
      )
  
      if any([file.lower().endswith("." + x) for x in image_types]):
          return (
              gr.update(visible=True, value=img_url),
              dummy1,
              dummy1,
              dummy1,
              dummy1,
              dummy1,
              dummy1,
              dummy1,
          )
      elif any([file.lower().endswith("." + x) for x in video_types]):
          return (
              dummy1,
              dummy1,
              dummy1,
              dummy1,
              dummy1,
              dummy1,
              dummy1,
              gr.update(visible=True, value=file),
          )
      elif any([file.lower().endswith("." + x) for x in audio_types]):
          return (
              dummy1,
              dummy1,
              dummy1,
              dummy1,
              dummy1,
              dummy1,
              gr.update(visible=True, value=file),
              dummy1,
          )
      elif file.lower().endswith(".pdf") or "arxiv.org/pdf" in file:
          # account for when use `wget -b -m -k -o wget.log -e robots=off`
          if url_alive("http://" + file):
              file = "http://" + file
          if url_alive("https://" + file):
              file = "https://" + file
  
          if file.lower().startswith("http") or file.lower().startswith(
              "https"
          ):
              # if file is online, then might as well use google(?)
              document1 = file
              return (
                  gr.update(
                      visible=True,
                      value=f"""<iframe width="1000" height="{pdf_height}" src="https://docs.google.com/viewerng/viewer?url={document1}&embedded=true" frameborder="0" height="100%" width="100%">
  </iframe>
  """,
                  ),
                  dummy1,
                  dummy1,
                  dummy1,
                  dummy1,
                  dummy1,
                  dummy1,
                  dummy1,
              )
          elif have_gradio_pdf and os.path.isfile(file):
              from gradio_pdf import PDF
  
              return (
                  dummy1,
                  dummy1,
                  dummy1,
                  dummy1,
                  dummy1,
                  PDF(
                      file,
                      visible=True,
                      label=file,
                      show_label=True,
                      height=pdf_height,
                  ),
                  dummy1,
                  dummy1,
              )
          else:
              return dummy_ret
      else:
          return dummy_ret
  
imports: import ast
  import copy
  import functools
  import inspect
  import itertools
  import json
  import os
  import pprint
  import random
  import shutil
  import sys
  import time
  import traceback
  import uuid
  import filelock
  import numpy
  import pandas
  import requests
  from iterators import TimeoutIterator
  from gradio_utils.css import get_css
  from gradio_utils.prompt_form import make_chatbots, get_chatbot_name
  from src.db_utils import set_userid, get_username_direct
  from src.tts_utils import combine_audios
  import gradio
  from enums import DocumentSubset, no_model_str, no_lora_str, no_server_str, LangChainAction, LangChainMode, DocumentChoice, langchain_modes_intrinsic, LangChainTypes, langchain_modes_non_db, gr_to_lg, invalid_key_msg, LangChainAgent, docs_ordering_types, docs_token_handlings, docs_joiner_default
  from gradio_themes import H2oTheme, SoftTheme, get_h2o_title, get_simple_title, get_dark_js, get_heap_js, wrap_js_to_lambda, spacing_xsm, radius_xsm, text_xsm
  from prompter import prompt_type_to_model_name, prompt_types_strings, inv_prompt_type_to_model_lower, non_hf_types, get_prompt, model_names_curated, get_system_prompts, get_llava_prompts
  from utils import flatten_list, zip_data, s3up, clear_torch_cache, get_torch_allocated, system_info_print, ping, makedirs, get_kwargs, system_info, ping_gpu, get_url, get_local_ip, save_generate_output, url_alive, remove, dict_to_html, text_to_html, lg_to_gr, str_to_dict, have_serpapi, have_librosa, have_gradio_pdf, have_pyrubberband, is_gradio_version4, have_fiftyone, n_gpus_global, _save_generate_tokens, get_accordion_named
  from gen import get_model, languages_covered, evaluate, score_qa, inputs_kwargs_list, get_max_max_new_tokens, get_minmax_top_k_docs, history_to_context, langchain_actions, langchain_agents_list, evaluate_fake, merge_chat_conversation_history, switch_a_roo_llama, get_model_max_length_from_tokenizer, get_model_retry, remove_refs, get_on_disk_models, get_llama_lower_hf, model_name_to_prompt_type
  from evaluate_params import eval_func_param_names, no_default_param_names, eval_func_param_names_defaults, input_args_list, key_overrides
  from apscheduler.schedulers.background import BackgroundScheduler
label_desc: Use image node_id 10 for calling a global function with example usage: show_doc(db1s, selection_docs_state1, requests_state1, langchain_mode1, single_document_choice1, view_raw_text_checkbox1, text_context_list1, pdf_height, dbs1, load_db_if_exists1, db_type1, use_openai_embedding1, hf_embedding_model1, migrate_embedding_model_or_db1, auto_migrate_db1, verbose1, get_userid_auth1, max_raw_chunks, api, n_jobs) and returns: dummy_ret, dummy1,  gr,  dummy1,  dummy1,  dummy1,  dummy1,  dummy1,  dummy1, gr,  dummy1,  dummy1,  dummy1,  dummy1,  dummy1,  dummy1,  dummy1, dict, dict, dummy_ret, gr,  dummy1,  dummy1,  dummy1,  dummy1,  dummy1,  dummy1,  dummy1, dummy1,  dummy1,  dummy1,  gr,  dummy1,  dummy1,  dummy1,  dummy1, dummy1,  dummy1,  dummy1,  gr,  dummy1,  dummy1,  dummy1,  dummy1, dummy1,  dummy1,  dummy1,  gr,  dummy1,  dummy1,  dummy1,  dummy1, dummy1,  dummy1,  dummy1,  dummy1,  dummy1,  dummy1,  dummy1,  gr, dummy_ret, dummy_ret, dummy_ret, dummy_ret, dummy1,  dummy1,  gr,  dummy1,  dummy1,  dummy1,  dummy1,  dummy1, dummy1,  dummy1,  dummy1,  dummy1,  dummy1,  dummy1,  gr,  dummy1, dummy_ret, gr,  dummy1,  dummy1,  dummy1,  dummy1,  dummy1,  dummy1,  dummy1, dummy1,  dummy1,  dummy1,  dummy1,  dummy1,  PDF,  dummy1,  dummy1, dummy_ret