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 <contactvarun27@gmail.com>
This commit is contained in:
parent
a8b8fcea32
commit
9039b4f32b
|
@ -1,3 +1,4 @@
|
|||
import os
|
||||
from pathlib import Path
|
||||
from typing import Optional
|
||||
|
||||
|
@ -12,6 +13,8 @@ from ktem.settings import BaseSettingGroup, SettingGroup, SettingReasoningGroup
|
|||
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 @@ class BaseApp:
|
|||
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()
|
||||
|
||||
|
|
|
@ -17,7 +17,7 @@ function onBlockLoad () {
|
|||
<span class="close" id="modal-expand">⛶</span>
|
||||
</div>
|
||||
<div class="modal-body">
|
||||
<pdfjs-viewer-element id="pdf-viewer" viewer-path="/file=PDFJS_PREBUILT_DIR" locale="en" phrase="true">
|
||||
<pdfjs-viewer-element id="pdf-viewer" viewer-path="GRADIO_ROOT_PATH/file=PDFJS_PREBUILT_DIR" locale="en" phrase="true">
|
||||
</pdfjs-viewer-element>
|
||||
</div>
|
||||
</div>
|
||||
|
|
|
@ -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 @@ class Render:
|
|||
|
||||
return f"""
|
||||
{html_content}
|
||||
<a href="#" class="pdf-link" data-src="/file={pdf_path}" data-page="{page_idx}" data-search="{highlight_text}" data-phrase="{phrase}">
|
||||
<a href="#" class="pdf-link" data-src="{BASE_PATH}/file={pdf_path}" data-page="{page_idx}" data-search="{highlight_text}" data-phrase="{phrase}">
|
||||
[Preview]
|
||||
</a>
|
||||
""" # noqa
|
||||
|
|
Loading…
Reference in New Issue
Block a user