Skip to content

Commit

Permalink
fix: using a base path breaks file preview (#575)
Browse files Browse the repository at this point in the history
* fix: using a base path breaks file preview

* fix: comfort precommit

---------

Co-authored-by: Varun Sharma <contactvarun27@gmail.com>
  • Loading branch information
taprosoft and varunsharma27 authored Dec 17, 2024
1 parent a8b8fce commit 9039b4f
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 4 deletions.
5 changes: 4 additions & 1 deletion libs/ktem/ktem/app.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import os
from pathlib import Path
from typing import Optional

Expand All @@ -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
Expand Down Expand Up @@ -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()

Expand Down
2 changes: 1 addition & 1 deletion libs/ktem/ktem/assets/js/pdf_viewer.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ function onBlockLoad () {
<span class="close" id="modal-expand">&#x26F6;</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>
Expand Down
6 changes: 4 additions & 2 deletions libs/ktem/ktem/utils/render.py
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -104,7 +106,7 @@ def preview(

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
Expand Down

0 comments on commit 9039b4f

Please sign in to comment.