From 9039b4f32b957cb8104d8a31a9937f59c8b20673 Mon Sep 17 00:00:00 2001 From: "Tuan Anh Nguyen Dang (Tadashi_Cin)" Date: Tue, 17 Dec 2024 17:12:27 +0700 Subject: [PATCH] fix: using a base path breaks file preview (#575) * fix: using a base path breaks file preview * fix: comfort precommit --------- Co-authored-by: Varun Sharma --- libs/ktem/ktem/app.py | 5 ++++- libs/ktem/ktem/assets/js/pdf_viewer.js | 2 +- libs/ktem/ktem/utils/render.py | 6 ++++-- 3 files changed, 9 insertions(+), 4 deletions(-) diff --git a/libs/ktem/ktem/app.py b/libs/ktem/ktem/app.py index 7142377e1..c4dce3564 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 10b32d9d3..63c600e8b 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 c42b8ad66..63e1ab5b4 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 @@ -104,7 +106,7 @@ def preview( return f""" {html_content} - + [Preview] """ # noqa