Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
chenpangpang
open-webui
Commits
380cb93e
Unverified
Commit
380cb93e
authored
Aug 01, 2024
by
Timothy Jaeryang Baek
Committed by
GitHub
Aug 01, 2024
Browse files
Merge pull request #4257 from thearyadev/fix/pdf-gen-static-path
fix: pdf gen static path resolution
parents
36e76627
b7ad4701
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
15 additions
and
2 deletions
+15
-2
backend/apps/webui/routers/utils.py
backend/apps/webui/routers/utils.py
+15
-2
No files found.
backend/apps/webui/routers/utils.py
View file @
380cb93e
from
pathlib
import
Path
import
site
from
fastapi
import
APIRouter
,
UploadFile
,
File
,
Response
from
fastapi
import
APIRouter
,
UploadFile
,
File
,
Response
from
fastapi
import
Depends
,
HTTPException
,
status
from
fastapi
import
Depends
,
HTTPException
,
status
from
starlette.responses
import
StreamingResponse
,
FileResponse
from
starlette.responses
import
StreamingResponse
,
FileResponse
...
@@ -64,8 +67,18 @@ async def download_chat_as_pdf(
...
@@ -64,8 +67,18 @@ async def download_chat_as_pdf(
pdf
=
FPDF
()
pdf
=
FPDF
()
pdf
.
add_page
()
pdf
.
add_page
()
STATIC_DIR
=
"./static"
# When running in docker, workdir is /app/backend, so fonts is in /app/backend/static/fonts
FONTS_DIR
=
f
"
{
STATIC_DIR
}
/fonts"
FONTS_DIR
=
Path
(
"./static/fonts"
)
# Non Docker Installation
# When running using `pip install` the static directory is in the site packages.
if
not
FONTS_DIR
.
exists
():
FONTS_DIR
=
Path
(
site
.
getsitepackages
()[
0
])
/
"static/fonts"
# When running using `pip install -e .` the static directory is in the site packages.
# This path only works if `open-webui serve` is run from the root of this project.
if
not
FONTS_DIR
.
exists
():
FONTS_DIR
=
Path
(
"./backend/static/fonts"
)
pdf
.
add_font
(
"NotoSans"
,
""
,
f
"
{
FONTS_DIR
}
/NotoSans-Regular.ttf"
)
pdf
.
add_font
(
"NotoSans"
,
""
,
f
"
{
FONTS_DIR
}
/NotoSans-Regular.ttf"
)
pdf
.
add_font
(
"NotoSans"
,
"b"
,
f
"
{
FONTS_DIR
}
/NotoSans-Bold.ttf"
)
pdf
.
add_font
(
"NotoSans"
,
"b"
,
f
"
{
FONTS_DIR
}
/NotoSans-Bold.ttf"
)
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment