Skip to content

Commit

Permalink
fix file uploader and endpoint
Browse files Browse the repository at this point in the history
  • Loading branch information
liberty-rising committed Jan 23, 2024
1 parent aa34b43 commit b546a70
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 8 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
6 changes: 5 additions & 1 deletion frontend/src/pages/upload/CreateDataProfileWindow.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -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) => {
Expand Down Expand Up @@ -68,7 +69,10 @@ function CreateDataProfileWindow({ 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
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
2 changes: 1 addition & 1 deletion frontend/src/pages/upload/UploadPage.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ function UploadPage() {
</Stack>

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

<Box mt={2}>
Expand Down

0 comments on commit b546a70

Please sign in to comment.