File size: 2,084 Bytes
9bc7a47
7ad07ce
 
 
9bc7a47
7ad07ce
2b38d79
7ad07ce
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
f044dce
 
 
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
import os
from fastapi import FastAPI, Form, HTTPException
from fastapi.middleware.cors import CORSMiddleware
from app.utils.ui_payload_constructor import UIPayload
from app.graph import graph
from app.utils.cloudinary_utils import get_resume_url
 
app = FastAPI(title="Adaptive Onboarding Engine")
 
app.add_middleware(
    CORSMiddleware,
    allow_origins=["*"],
    allow_methods=["*"],
    allow_headers=["*"],
)
 
@app.post("/analyze")
async def analyze(
    user_id: str = Form(..., description="User ID — used to fetch resume from Cloudinary"),
    job_description: str = Form(..., description="Job description text"),
):
    # 1. Fetch PDF URL from Cloudinary using user_id
    try:
        pdf_url = get_resume_url(user_id)
    except FileNotFoundError as e:
        raise HTTPException(status_code=404, detail=str(e))
 
    # 2. Build graph state
    initial_input = {
        "candidate_name": None,
        "resume_text": None,
        "file_path": pdf_url,
        "job_description": job_description,
        "resume_data": None,
        "extraction_error": None,
        "JobDescriptionExtract_data": None,
        "skill_gap_analysis_data": None,
        "messages": [],
        "mermaid_code": None,
        "final_roadmap": None,
    }
 
    # 3. Run graph — use user_id as thread_id for checkpointer
    config = {"configurable": {"thread_id": user_id}}
 
    try:
        final_state = graph.invoke(initial_input, config=config)
 
        if final_state.get("extraction_error"):
            raise HTTPException(
                status_code=422,
                detail=f"Extraction failed: {final_state['extraction_error']}"
            )
 
        payload = UIPayload.from_state(final_state)
        return payload.to_dict()
 
    except HTTPException:
        raise
    except Exception as e:
        raise HTTPException(status_code=500, detail=str(e))
 
 
@app.get("/health")
def health():
    return {"status": "ok", "service": "Adaptive Onboarding Engine"}
 
 
if __name__ == "__main__":
    import uvicorn
    uvicorn.run(app, host="127.0.0.1", port=8000)