From 63590a42e639dab464c54c9fa9fcf43ce9e281d4 Mon Sep 17 00:00:00 2001 From: Varun Sharma Date: Thu, 12 Dec 2024 20:59:54 +0000 Subject: [PATCH 1/2] fix: using a base path breaks file preview --- libs/ktem/ktem/app.py | 4 ++++ libs/ktem/ktem/assets/js/pdf_viewer.js | 2 +- libs/ktem/ktem/utils/render.py | 5 +++-- 3 files changed, 8 insertions(+), 3 deletions(-) diff --git a/libs/ktem/ktem/app.py b/libs/ktem/ktem/app.py index 7142377e1..8eb77851d 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,7 @@ 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,6 +56,8 @@ 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 9bab73186..7a08729ef 100644 --- a/libs/ktem/ktem/utils/render.py +++ b/libs/ktem/ktem/utils/render.py @@ -1,10 +1,11 @@ -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 +99,7 @@ def preview( return f""" {html_content} - + [Preview] """ # noqa From c16051cdc930ccb361746266173ff63b040c70bf Mon Sep 17 00:00:00 2001 From: Tadashi Date: Tue, 17 Dec 2024 17:05:37 +0700 Subject: [PATCH 2/2] fix: comfort precommit --- libs/ktem/ktem/app.py | 7 +++---- libs/ktem/ktem/utils/render.py | 3 ++- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/libs/ktem/ktem/app.py b/libs/ktem/ktem/app.py index 8eb77851d..c4dce3564 100644 --- a/libs/ktem/ktem/app.py +++ b/libs/ktem/ktem/app.py @@ -13,7 +13,8 @@ from theflow.settings import settings from theflow.utils.modules import import_dotted_string -BASE_PATH = os.environ.get('GRADIO_ROOT_PATH', '') +BASE_PATH = os.environ.get("GRADIO_ROOT_PATH", "") + class BaseApp: """The main app of Kotaemon @@ -56,9 +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 - ) + ).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/utils/render.py b/libs/ktem/ktem/utils/render.py index 7a08729ef..28039e90d 100644 --- a/libs/ktem/ktem/utils/render.py +++ b/libs/ktem/ktem/utils/render.py @@ -5,7 +5,8 @@ from kotaemon.base import RetrievedDocument -BASE_PATH = os.environ.get('GRADIO_ROOT_PATH', '') +BASE_PATH = os.environ.get("GRADIO_ROOT_PATH", "") + def is_close(val1, val2, tolerance=1e-9): return abs(val1 - val2) <= tolerance