Skip to content

Commit

Permalink
fix: using a base path breaks file preview
Browse files Browse the repository at this point in the history
  • Loading branch information
varunsharma27 authored Dec 12, 2024
1 parent a0c9a6e commit 63590a4
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 3 deletions.
4 changes: 4 additions & 0 deletions 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,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
Expand Down Expand Up @@ -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()
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
5 changes: 3 additions & 2 deletions libs/ktem/ktem/utils/render.py
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -98,7 +99,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 63590a4

Please sign in to comment.