File size: 993 Bytes
57cab59
 
 
 
819bacd
fe7c659
819bacd
 
fe7c659
 
819bacd
 
57cab59
 
 
 
 
 
819bacd
 
 
 
 
57cab59
 
 
819bacd
57cab59
 
 
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
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))