File size: 2,903 Bytes
c7bd3fe
 
67ba1ec
a704218
c7bd3fe
2bb85a3
a02f5b2
2bb85a3
a704218
c7bd3fe
 
 
2bb85a3
 
c7bd3fe
67757d4
91aab29
a704218
 
67ba1ec
 
 
 
 
 
 
 
 
 
 
 
91aab29
67ba1ec
c7bd3fe
 
67ba1ec
c7bd3fe
 
 
67ba1ec
c7bd3fe
a704218
 
 
 
c7bd3fe
 
a02f5b2
 
 
2bb85a3
a02f5b2
 
a704218
a02f5b2
a704218
a02f5b2
 
 
 
 
 
 
 
 
 
a704218
67ba1ec
 
2bb85a3
67ba1ec
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
from fastapi import APIRouter, HTTPException
from app.models.schema import GenerateRequest, GenerateResponse
from app.services.generator import coverLetterGenerativeAIBot
from app.services.resume_parser import extract_resume_text
from app.utils.file_utils import generate_unique_filename
from fastapi import UploadFile, File,Depends
from app.services.hf_storage_service import HuggingFaceStorageService
from app.auth.auth import verify_token
storage_service = HuggingFaceStorageService()

router = APIRouter()

@router.post("/generate", response_model=GenerateResponse,)
async def generate_cover_letter_api(data: GenerateRequest,user=Depends(verify_token)):
    try:
        if len(data.job_details) > 8192:
            raise HTTPException(status_code=400, detail="Job detail is too long")

        resume_text = extract_resume_text(data.resume_path)
        letter_text = await coverLetterGenerativeAIBot(data, resume_text)
        
        # md_cover_letter = build_cover_letter_md(
        #     your_name=data.full_name,
        #     postal_code=data.postal_code,
        #     city=data.city,
        #     email=data.email,
        #     phone=data.phone_number,
        #     job_title=data.job_title,
        #     company_name=data.company_name,
        #     generated_paragraphs=letter_text
        # )

        # text_cover_letter = convert_md_to_text(md_cover_letter)

        filename = generate_unique_filename()
        # pdf_path = save_pdf(text_cover_letter, filename)

        return GenerateResponse(
            letter=letter_text,
            pdf_url=""
        )

    except HTTPException as http_exc:
        raise http_exc

    except Exception as e:
        raise HTTPException(status_code=500, detail=str(e))


@router.post("/upload-resume")
async def upload_resume(resume: UploadFile = File(...),user=Depends(verify_token)):
    try:
        resume_content = await resume.read()
        resume_url = storage_service.upload_file_to_hf(
            file_content=resume_content,
            folder="resumes",
            filename=resume.filename
        )
        return {
            "success": True,
            "url": resume_url
        }
    except Exception as e:
        return {
            "success": False,
            "error": str(e)
        }
     
@router.post("/upload-file")
async def upload_file(pdf: UploadFile = File(...),user=Depends(verify_token)):
    try:
        # Read resume content
        pdf_content = await pdf.read()
        
        # Upload to HuggingFace Hub
        pdf_url = storage_service.upload_file_to_hf(
            file_content=pdf_content,
            folder="cover-letters",
            filename=pdf.filename
        )
        
        return {
            "success": True,
            "url": pdf_url
        }
        
    except Exception as e:
        return {
            "success": False,
            "error": str(e)
        }