From 8f20d51d1110710c148ba1728a8c0f64f39acdfd Mon Sep 17 00:00:00 2001 From: liberty-rising Date: Tue, 23 Jan 2024 18:34:26 +0100 Subject: [PATCH 1/3] rename files and variables --- ...{CreateDataProfilePage.jsx => CreateDataProfileWindow.jsx} | 4 ++-- frontend/src/pages/upload/UploadPage.jsx | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) rename frontend/src/pages/upload/{CreateDataProfilePage.jsx => CreateDataProfileWindow.jsx} (97%) diff --git a/frontend/src/pages/upload/CreateDataProfilePage.jsx b/frontend/src/pages/upload/CreateDataProfileWindow.jsx similarity index 97% rename from frontend/src/pages/upload/CreateDataProfilePage.jsx rename to frontend/src/pages/upload/CreateDataProfileWindow.jsx index b2c7213..41f3b64 100644 --- a/frontend/src/pages/upload/CreateDataProfilePage.jsx +++ b/frontend/src/pages/upload/CreateDataProfileWindow.jsx @@ -14,7 +14,7 @@ import FileUploader from "./FileUploader"; import PreviewTable from "./PreviewTable"; import { API_URL } from "../../utils/constants"; -function CreateDataProfilePage({ open, onClose, onCreate }) { +function CreateDataProfileWindow({ open, onClose, onCreate }) { const [name, setName] = useState(""); const [extractInstructions, setExtractInstructions] = useState(""); const [sampleFiles, setSampleFiles] = useState([]); @@ -112,4 +112,4 @@ function CreateDataProfilePage({ open, onClose, onCreate }) { ); } -export default CreateDataProfilePage; +export default CreateDataProfileWindow; diff --git a/frontend/src/pages/upload/UploadPage.jsx b/frontend/src/pages/upload/UploadPage.jsx index 0e175d0..c0e1e71 100644 --- a/frontend/src/pages/upload/UploadPage.jsx +++ b/frontend/src/pages/upload/UploadPage.jsx @@ -8,7 +8,7 @@ import { } from "@mui/material"; import axios from "axios"; import AlertSnackbar from "./AlertSnackbar"; -import CreateDataProfilePage from "./CreateDataProfilePage"; +import CreateDataProfileWindow from "./CreateDataProfileWindow"; import DataProfileSelector from "./DataProfileSelector"; import FileUploader from "./FileUploader"; import PreviewTable from "./PreviewTable"; @@ -137,7 +137,7 @@ function UploadPage() { > Create a data profile - setShowCreateDataProfile(false)} onCreate={handleCreateDataProfile} From aa34b43c60de42b9f5f59ba675df30622983f98d Mon Sep 17 00:00:00 2001 From: liberty-rising Date: Tue, 23 Jan 2024 18:39:28 +0100 Subject: [PATCH 2/3] rename files and variables --- frontend/src/pages/upload/UploadPage.jsx | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/frontend/src/pages/upload/UploadPage.jsx b/frontend/src/pages/upload/UploadPage.jsx index c0e1e71..40815a3 100644 --- a/frontend/src/pages/upload/UploadPage.jsx +++ b/frontend/src/pages/upload/UploadPage.jsx @@ -15,7 +15,7 @@ import PreviewTable from "./PreviewTable"; import { API_URL } from "../../utils/constants"; function UploadPage() { - const [files, setFiles] = useState([]); + const [uploadFiles, setUploadFiles] = useState([]); const [dataProfile, setDataProfile] = useState(null); const [dataProfiles, setDataProfiles] = useState([]); const [alertInfo, setAlertInfo] = useState({ @@ -54,10 +54,10 @@ function UploadPage() { }; const handlePreview = () => { - if (files.length && dataProfile) { + if (uploadFiles.length && dataProfile) { setIsPreviewLoading(true); const formData = new FormData(); - files.forEach((file) => { + uploadFiles.forEach((file) => { formData.append("files", file); // Append each file }); @@ -81,7 +81,7 @@ function UploadPage() { const handleSubmit = async () => { const formData = new FormData(); - formData.append("file", files); + formData.append("file", uploadFiles); formData.append("extra_desc", description); formData.append("is_new_table", isNewTable === "yes"); formData.append("encoding", encoding); @@ -145,7 +145,7 @@ function UploadPage() { - + @@ -160,7 +160,7 @@ function UploadPage() { variant="contained" color="secondary" onClick={handlePreview} - disabled={!files.length || !dataProfile || isPreviewLoading} + disabled={!uploadFiles.length || !dataProfile || isPreviewLoading} > Preview @@ -169,7 +169,7 @@ function UploadPage() { color="primary" onClick={handleSubmit} disabled={ - !files || + !uploadFiles || !dataProfile || !previewData || !isPreviewTableOpen || From b546a70d4e7a9b51e83ba56ae840490840872065 Mon Sep 17 00:00:00 2001 From: liberty-rising Date: Tue, 23 Jan 2024 21:43:36 +0100 Subject: [PATCH 3/3] fix file uploader and endpoint --- backend/llms/gpt.py | 2 +- backend/routes/data_profile_routes.py | 8 ++++++-- frontend/src/pages/upload/CreateDataProfileWindow.jsx | 6 +++++- frontend/src/pages/upload/FileUploader.jsx | 6 +++--- frontend/src/pages/upload/UploadPage.jsx | 2 +- 5 files changed, 16 insertions(+), 8 deletions(-) diff --git a/backend/llms/gpt.py b/backend/llms/gpt.py index a2bfc1b..4b03d4c 100644 --- a/backend/llms/gpt.py +++ b/backend/llms/gpt.py @@ -408,7 +408,7 @@ async def extract_data_from_jpgs( self._add_system_message(assistant_type="jpg_data_extraction") self._set_model(model_type="img") - instructions = data_profile.description + instructions = data_profile.extract_instructions prompt = self.prompt_manager.jpg_data_extraction_prompt(instructions) assistant_message_content = await self._send_and_receive_message( diff --git a/backend/routes/data_profile_routes.py b/backend/routes/data_profile_routes.py index 67f7290..4d6cb72 100644 --- a/backend/routes/data_profile_routes.py +++ b/backend/routes/data_profile_routes.py @@ -80,9 +80,13 @@ async def get_data_profile( @data_profile_router.post("/data-profiles/preview/") async def preview_data_profile( files: List[UploadFile] = File(...), - instructions: str = Form(...), + extract_instructions: str = Form(...), current_user: User = Depends(get_current_user), ): + preview_data_profile = DataProfile( + name="preview", extract_instructions=extract_instructions + ) + temp_file_paths = [] for file in files: if file.filename: @@ -113,7 +117,7 @@ async def preview_data_profile( jpg_presigned_urls = space_manager.create_presigned_urls() gpt = GPTLLM(chat_id=1, user=current_user) extracted_data = await gpt.extract_data_from_jpgs( - instructions, jpg_presigned_urls + preview_data_profile, jpg_presigned_urls ) # Delete the temporary files diff --git a/frontend/src/pages/upload/CreateDataProfileWindow.jsx b/frontend/src/pages/upload/CreateDataProfileWindow.jsx index 41f3b64..12748e8 100644 --- a/frontend/src/pages/upload/CreateDataProfileWindow.jsx +++ b/frontend/src/pages/upload/CreateDataProfileWindow.jsx @@ -29,6 +29,7 @@ function CreateDataProfileWindow({ open, onClose, onCreate }) { const handlePreview = () => { if (sampleFiles.length && extractInstructions) { + console.log(extractInstructions); setIsPreviewLoading(true); const formData = new FormData(); sampleFiles.forEach((file) => { @@ -68,7 +69,10 @@ function CreateDataProfileWindow({ open, onClose, onCreate }) { /> - + { +const FileUploader = ({ setFiles, id }) => { const [fileNames, setFileNames] = useState([]); const [fileType, setFileType] = useState(null); @@ -85,12 +85,12 @@ const FileUploader = ({ setFiles }) => { > -