Spaces:
Sleeping
Sleeping
File size: 1,031 Bytes
4810f6f 99ab820 4810f6f 5a97ebf 99ab820 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 |
import os
from fastapi import UploadFile
from app.vector_store import store_pdf, store_pdf_image, store_pdf_image_text
UPLOAD_DIR = "data/uploaded_pdfs"
def process_pdf(file: UploadFile):
os.makedirs(UPLOAD_DIR, exist_ok=True)
filepath = os.path.join(UPLOAD_DIR, file.filename)
with open(filepath, "wb") as f:
f.write(file.file.read())
store_pdf(filepath)
return {"status": "uploaded", "filename": file.filename}
def process_image_pdf(file: UploadFile):
os.makedirs(UPLOAD_DIR, exist_ok=True)
filepath = os.path.join(UPLOAD_DIR, file.filename)
with open(filepath, "wb") as f:
f.write(file.file.read())
store_pdf_image(filepath)
return {"status": "uploaded", "filename": file.filename}
def process_image_pdf_dummy():
try:
with open("output.txt", "r") as f:
content = f.read()
print(f'{content}')
except FileNotFoundError:
return {"error": "File not found"}
store_pdf_image_text(content)
return {"status": "uploaded"}
|