File size: 1,540 Bytes
7796444
 
 
 
 
 
53d57fc
 
 
 
 
7796444
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
36
37
import docx

from fastapi import APIRouter
from app.modules.matching_cv.models.match_cv_jd_model import Match_JD_CV_Model

from app.modules.matching_cv.models.matching_cv_logic import result_matching_cv_jd, load_jd_from_id

cvmatching_router = APIRouter(prefix="/cvmatching", tags=["cvmatching"])

@cvmatching_router.get("/")
async def index():
    return {"message": "Welcome to CV matching page"}

@cvmatching_router.post("/matching")
# only upload .pdf or .docx file
async def matching_cv_jd(
    jd_upload: Match_JD_CV_Model.jd = Match_JD_CV_Model.jd_default, 
    cv_upload: Match_JD_CV_Model.cv = Match_JD_CV_Model.cv_default):
    try:
        # take jd_upload and cv_upload type file
        jd_upload_type = jd_upload.filename.split(".")[-1]
        cv_upload_type = cv_upload.filename.split(".")[-1]
        if jd_upload_type in ["txt"] and cv_upload_type in ["pdf", "docx"]:
            jd_text =  jd_upload.file.read().decode("utf-8")
            if cv_upload_type == "docx":
                cv_text = docx.Document(cv_upload.file).paragraphs
                cv_text = "\n".join([i.text for i in cv_text])
            elif cv_upload_type == "pdf":
                return {"message": "This feature is not available yet"}
            # check matching cv and jd
            result = result_matching_cv_jd(cv_text, jd_text)
            return {"result": result}
        else:
            return {"message": "Please upload only .txt for JD. And .pdf or .docx file for CV"}
    except Exception as e:
        return {"Error": str(e)}