Skip to content

Commit

Permalink
data extraction from jpg llm
Browse files Browse the repository at this point in the history
  • Loading branch information
rezart95 committed Jan 6, 2024
1 parent dc1ba66 commit d75f444
Showing 1 changed file with 7 additions and 12 deletions.
19 changes: 7 additions & 12 deletions backend/routes/data_profile_routes.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
from fastapi import APIRouter, HTTPException, Depends, UploadFile, File, Form

# from starlette.responses import JSONResponse
import tempfile
import os

from database.database_manager import DatabaseManager
from database.data_profile_manager import DataProfileManager
Expand Down Expand Up @@ -70,19 +68,16 @@ async def preview_data_profile(
):
suffix = file.filename.split(".")[-1]
# Save the uploaded file temporarily
with tempfile.NamedTemporaryFile(delete=False, suffix=suffix) as temp_file:
with tempfile.NamedTemporaryFile(delete=True, suffix=suffix) as temp_file:
temp_file.write(await file.read())
temp_file_path = temp_file.name

# Use the ImageConversionManager context manager to convert the PDF to JPG
with ImageConversionManager(temp_file_path, "/tmp/") as manager:
jpg_file = manager.convert_to_jpg(temp_file_path)
gpt = GPTLLM()
data = gpt.extract_data_from_jpg(instructions, jpg_file)

# Clean up the uploaded temp file
os.unlink(temp_file_path)
return data
# Use the ImageConversionManager context manager to convert the PDF to JPG
with ImageConversionManager(temp_file_path, "/tmp/") as manager:
jpg_file = manager.convert_to_jpg(temp_file_path)
gpt = GPTLLM()
data = gpt.extract_data_from_jpg(instructions, jpg_file)
return data


# the response has to be a json
Expand Down

0 comments on commit d75f444

Please sign in to comment.