Skip to content

Commit

Permalink
Merge pull request #240 from DocShow-AI/fix_upload
Browse files Browse the repository at this point in the history
Fix upload
  • Loading branch information
liberty-rising authored Jan 23, 2024
2 parents 8b135b0 + b546a70 commit 307ee4a
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 18 deletions.
2 changes: 1 addition & 1 deletion backend/llms/gpt.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
8 changes: 6 additions & 2 deletions backend/routes/data_profile_routes.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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([]);
Expand All @@ -29,6 +29,7 @@ function CreateDataProfilePage({ open, onClose, onCreate }) {

const handlePreview = () => {
if (sampleFiles.length && extractInstructions) {
console.log(extractInstructions);
setIsPreviewLoading(true);
const formData = new FormData();
sampleFiles.forEach((file) => {
Expand Down Expand Up @@ -68,7 +69,10 @@ function CreateDataProfilePage({ open, onClose, onCreate }) {
/>
</Box>
<Box mt={2}>
<FileUploader setFiles={setSampleFiles} />
<FileUploader
setFiles={setSampleFiles}
id="create-data-profile-uploader"
/>
</Box>
<Box mt={2}>
<TextField
Expand Down Expand Up @@ -112,4 +116,4 @@ function CreateDataProfilePage({ open, onClose, onCreate }) {
);
}

export default CreateDataProfilePage;
export default CreateDataProfileWindow;
6 changes: 3 additions & 3 deletions frontend/src/pages/upload/FileUploader.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import React, { useState } from "react";
import { Box, Typography, IconButton } from "@mui/material";
import DeleteIcon from "@mui/icons-material/Delete";

const FileUploader = ({ setFiles }) => {
const FileUploader = ({ setFiles, id }) => {
const [fileNames, setFileNames] = useState([]);
const [fileType, setFileType] = useState(null);

Expand Down Expand Up @@ -85,12 +85,12 @@ const FileUploader = ({ setFiles }) => {
>
<input
type="file"
id="contained-button-file"
id={id}
style={{ display: "none" }}
onChange={handleFileChange}
multiple
/>
<label htmlFor="contained-button-file">
<label htmlFor={id}>
<Typography variant="body1" component="span">
{fileNames.length === 0
? "Drag 'n' drop some files here, or click to select files"
Expand Down
18 changes: 9 additions & 9 deletions frontend/src/pages/upload/UploadPage.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,14 @@ 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";
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({
Expand Down Expand Up @@ -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
});

Expand All @@ -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);
Expand Down Expand Up @@ -137,15 +137,15 @@ function UploadPage() {
>
Create a data profile
</Button>
<CreateDataProfilePage
<CreateDataProfileWindow
open={showCreateDataProfile}
onClose={() => setShowCreateDataProfile(false)}
onCreate={handleCreateDataProfile}
/>
</Stack>

<Box mt={2}>
<FileUploader setFiles={setFiles} />
<FileUploader setFiles={setUploadFiles} id="upload-page-uploader" />
</Box>

<Box mt={2}>
Expand All @@ -160,7 +160,7 @@ function UploadPage() {
variant="contained"
color="secondary"
onClick={handlePreview}
disabled={!files.length || !dataProfile || isPreviewLoading}
disabled={!uploadFiles.length || !dataProfile || isPreviewLoading}
>
Preview
</Button>
Expand All @@ -169,7 +169,7 @@ function UploadPage() {
color="primary"
onClick={handleSubmit}
disabled={
!files ||
!uploadFiles ||
!dataProfile ||
!previewData ||
!isPreviewTableOpen ||
Expand Down

0 comments on commit 307ee4a

Please sign in to comment.