-
Notifications
You must be signed in to change notification settings - Fork 3
/
api.py
40 lines (28 loc) · 1.14 KB
/
api.py
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
from typing import Annotated
from fastapi import FastAPI, APIRouter, UploadFile, Form
from fastapi.staticfiles import StaticFiles
from llama_cpu import load_model, resume_to_job
from helpers import create_session_data
import os
from pyppeteer import launch
from pyppeteer_stealth import stealth
pyppeteer_browser = {}
app = FastAPI()
app.mount("/frontend", StaticFiles(directory="frontend"), name="frontend")
router = APIRouter()
browser = None
@app.on_event("startup")
async def startup_event():
browser = await launch()
page = await browser.newPage()
await stealth(page)
pyppeteer_browser['page'] = page
if os.path.exists("sessions") is not True:
os.mkdir('sessions')
app.llm_chain = load_model()
@router.post("/convert")
async def convert_resume(my_resume: UploadFile, job_ad_url: Annotated[str, Form()], session: Annotated[str, Form()]):
resume_path = await create_session_data(session, my_resume)
new_resume = await resume_to_job(resume_path, job_ad_url, session, app.llm_chain, pyppeteer_browser['page'])
return {"newResume": new_resume}
app.include_router(router, prefix="/api")