diff --git a/libs/ktem/ktem/app.py b/libs/ktem/ktem/app.py index 7142377e..c4dce356 100644 --- a/libs/ktem/ktem/app.py +++ b/libs/ktem/ktem/app.py @@ -1,3 +1,4 @@ +import os from pathlib import Path from typing import Optional @@ -12,6 +13,8 @@ from theflow.settings import settings from theflow.utils.modules import import_dotted_string +BASE_PATH = os.environ.get("GRADIO_ROOT_PATH", "") + class BaseApp: """The main app of Kotaemon @@ -54,7 +57,7 @@ def __init__(self): self._pdf_view_js = self._pdf_view_js.replace( "PDFJS_PREBUILT_DIR", pdf_js_dist_dir, - ) + ).replace("GRADIO_ROOT_PATH", BASE_PATH) with (dir_assets / "js" / "svg-pan-zoom.min.js").open() as fi: self._svg_js = fi.read() diff --git a/libs/ktem/ktem/assets/js/pdf_viewer.js b/libs/ktem/ktem/assets/js/pdf_viewer.js index 10b32d9d..63c600e8 100644 --- a/libs/ktem/ktem/assets/js/pdf_viewer.js +++ b/libs/ktem/ktem/assets/js/pdf_viewer.js @@ -17,7 +17,7 @@ function onBlockLoad () { diff --git a/libs/ktem/ktem/utils/render.py b/libs/ktem/ktem/utils/render.py index 9bab7318..28039e90 100644 --- a/libs/ktem/ktem/utils/render.py +++ b/libs/ktem/ktem/utils/render.py @@ -1,10 +1,12 @@ -import os.path +import os import markdown from fast_langdetect import detect from kotaemon.base import RetrievedDocument +BASE_PATH = os.environ.get("GRADIO_ROOT_PATH", "") + def is_close(val1, val2, tolerance=1e-9): return abs(val1 - val2) <= tolerance @@ -98,7 +100,7 @@ def preview( return f""" {html_content} - + [Preview] """ # noqa