Spaces:
Sleeping
Sleeping
from typing import Any | |
from fastapi import HTTPException, UploadFile | |
from fastapi.responses import JSONResponse | |
from app.modules.uploadDocument.features.createEmbeddings_feature import ( | |
CreateEmbeddingsFeature, | |
) | |
from app.modules.uploadDocument.features.extractText_feature import ExtractTextFeature | |
from app.modules.uploadDocument.features.uploadDocument_feature import ( | |
UploadDocumentFeature, | |
) | |
class FileUploadController: | |
async def handle_file_upload(self, file: UploadFile) -> Any: | |
try: | |
text_file = await ExtractTextFeature.extract_text_from_pdf(file) | |
await CreateEmbeddingsFeature.create_embeddings(text_file, file.filename) | |
result = await UploadDocumentFeature.uploadFile(file) | |
message = result.get("message", "No message provided") | |
return JSONResponse(status_code=200, content={"message": message}) | |
except Exception as e: | |
raise HTTPException(status_code=500, detail=str(e)) | |