From 72e963f269bdfb83bf17e46d8427b94c0dcb5822 Mon Sep 17 00:00:00 2001 From: Jojo Ortiz Date: Tue, 21 Nov 2023 16:54:50 -0800 Subject: [PATCH] add drag and drop file upload capability --- pykoi/frontend/src/assets/CloudArrowUp.svelte | 4 + pykoi/frontend/src/lib/RAG/RAG.svelte | 77 ++++++++++++++++--- 2 files changed, 71 insertions(+), 10 deletions(-) create mode 100644 pykoi/frontend/src/assets/CloudArrowUp.svelte diff --git a/pykoi/frontend/src/assets/CloudArrowUp.svelte b/pykoi/frontend/src/assets/CloudArrowUp.svelte new file mode 100644 index 0000000..a0239fb --- /dev/null +++ b/pykoi/frontend/src/assets/CloudArrowUp.svelte @@ -0,0 +1,4 @@ + + \ No newline at end of file diff --git a/pykoi/frontend/src/lib/RAG/RAG.svelte b/pykoi/frontend/src/lib/RAG/RAG.svelte index 17cab22..190d84c 100644 --- a/pykoi/frontend/src/lib/RAG/RAG.svelte +++ b/pykoi/frontend/src/lib/RAG/RAG.svelte @@ -3,12 +3,33 @@ import Table from "./Components/tanstackTable/Table.svelte"; import { onMount } from "svelte"; import { uploadedFiles, projections } from "../store.js"; + import CloudArrowUp from "../../assets/CloudArrowUp.svelte"; let selectedFiles = []; let indexed = false; let indexing = false; async function handleFileChange(event) { - selectedFiles = event.target.files; + event.preventDefault(); + let selectedFiles = []; + if (event.dataTransfer) { + if (event.dataTransfer.items) { + // Use DataTransferItemList interface to access the file(s) + [...event.dataTransfer.items].forEach((item, i) => { + // If dropped items aren't files, reject them + if (item.kind === "file") { + const file = item.getAsFile(); + selectedFiles.push(file); + } + }); + } else { + // Use DataTransfer interface to access the file(s) + [...event.dataTransfer.files].forEach((file, i) => { + selectedFiles.push(file); + }); + } + } else { + selectedFiles = event.target.files; + } const formData = new FormData(); // iterate over selectedFiles and add them to array for (let i = 0; i < selectedFiles.length; i++) { @@ -56,6 +77,12 @@ $projections = embeddingData; } + function dragOverHandler(event) { + console.log("File(s) in drop zone"); + // Prevent default behavior (Prevent file from being opened) + event.preventDefault(); + } + onMount(() => { loadServerData(); }); @@ -76,18 +103,27 @@

Upload Data

-
-
- -
+

These are the files your model will use as context.

+
+
+ +
+
+ + Drag and drop files here +
+
{#if indexing && !indexed}

{dots}

{/if} {#if indexed}

Data Successfully indexed!

{/if} -

These are the files your model will use as context.

-

Currently pdf, txt, and md are supported.

+

Currently pdf, txt, and md are supported.

@@ -100,6 +136,17 @@