From ba5f9b105f0dc9216519bea4759484ddd0fceca4 Mon Sep 17 00:00:00 2001 From: Mishig Davaadorj Date: Tue, 9 Jan 2024 10:39:03 +0100 Subject: [PATCH] `ENABLE_PDF_CHAT` env var --- .env | 2 ++ src/lib/components/UploadBtn.svelte | 9 ++++++--- src/lib/components/chat/ChatWindow.svelte | 6 ++++-- src/routes/+layout.server.ts | 4 ++++ 4 files changed, 16 insertions(+), 5 deletions(-) diff --git a/.env b/.env index c4d23840998..b589baa1502 100644 --- a/.env +++ b/.env @@ -104,6 +104,8 @@ PUBLIC_APP_DATA_SHARING=#set to 1 to enable options & text regarding data sharin PUBLIC_APP_DISCLAIMER=#set to 1 to show a disclaimer on login page LLM_SUMMERIZATION=true +ENABLE_PDF_CHAT=false #set to true to enable PDF-chat feature + # PUBLIC_APP_NAME=HuggingChat # PUBLIC_APP_ASSETS=huggingchat # PUBLIC_APP_COLOR=yellow diff --git a/src/lib/components/UploadBtn.svelte b/src/lib/components/UploadBtn.svelte index 62b87316cee..2c8005b9a0c 100644 --- a/src/lib/components/UploadBtn.svelte +++ b/src/lib/components/UploadBtn.svelte @@ -6,10 +6,13 @@ export let classNames = ""; export let multimodal = false; + export let pdfChat = false; export let files: File[]; export let pdfUpload: PdfUpload | undefined = undefined; - const accept = multimodal ? "image/*,.pdf" : ".pdf"; - const label = multimodal ? "Upload image or PDF" : "Upload PDF"; + + const accept = (multimodal && pdfChat) ? "image/*,.pdf" : multimodal ? "image/*" : ".pdf"; + const label = (multimodal && pdfChat) ? "Upload image or PDF" : multimodal ? "Upload image" : "Upload PDF"; + let fileInput: HTMLInputElement; let interval: ReturnType; @@ -35,7 +38,7 @@ } const file = fileInput.files?.[0]; - if (file?.type === "application/pdf") { + if (pdfChat && file?.type === "application/pdf") { // pdf upload dispatch("uploadpdf", file); } else if (multimodal && file?.type.startsWith("image")) { diff --git a/src/lib/components/chat/ChatWindow.svelte b/src/lib/components/chat/ChatWindow.svelte index 8bf5246d26f..9adf870db1b 100644 --- a/src/lib/components/chat/ChatWindow.svelte +++ b/src/lib/components/chat/ChatWindow.svelte @@ -157,10 +157,12 @@ /> {/if}
- {#if pdfUpload?.name} + {#if $page.data.enablePdfChat && pdfUpload?.name} {/if} - + {#if currentModel.multimodal || $page.data.enablePdfChat} + + {/if}
{ @@ -58,6 +59,8 @@ export const load: LayoutServerLoad = async ({ locals, depends }) => { const loginRequired = requiresUser && !locals.user && userHasExceededMessages; + const enablePdfChat = ENABLE_PDF_CHAT === "true"; + return { conversations: await conversations .find(authCondition(locals)) @@ -111,5 +114,6 @@ export const load: LayoutServerLoad = async ({ locals, depends }) => { loginRequired, loginEnabled: requiresUser, guestMode: requiresUser && messagesBeforeLogin > 0, + enablePdfChat, }; };