CoolFace
Apppublic

ijsasif/Module-1-Skill-Extractor

sourceHugging Facemitupdated 3mo agoView on Hugging Face
0likes
app.py99 linesDownload Raw Back to root
1"""2app.py - TalentPulse Module 1 Skill Extraction API3Deployed on Hugging Face Spaces (Docker SDK), port 7860.4"""5 6from typing import Literal7 8from fastapi import FastAPI, File, HTTPException, Query, UploadFile9from fastapi.middleware.cors import CORSMiddleware10from pydantic import BaseModel, Field11 12from inference import extract_skills_from_bytes, extract_skills_from_text, extract_text_from_upload, get_runtime_status13 14Mode = Literal["gliner"]15 16app = FastAPI(17    title="TalentPulse Skill Extractor API",18    description="Resume skill extraction API for Module 1 using GLiNER-categorized skill extraction.",19    version="1.0.0",20)21 22app.add_middleware(23    CORSMiddleware,24    allow_origins=["*"],25    allow_credentials=True,26    allow_methods=["*"],27    allow_headers=["*"],28)29 30 31class TextPayload(BaseModel):32    text: str = Field(..., min_length=1, description="Resume text to analyze")33 34 35@app.get("/", tags=["Health"])36def root():37    status = get_runtime_status()38    return {39        "status": "ok",40        "service": "TalentPulse Skill Extractor API",41        "version": "1.0.0",42        "default_mode": "gliner",43        "gliner_model": status["gliner_model"],44        "gliner_loaded": status["gliner_loaded"],45        "supported_extensions": status["supported_extensions"],46    }47 48 49@app.get("/health", tags=["Health"])50def health():51    return get_runtime_status()52 53 54@app.post("/extract-skills", tags=["Inference"])55async def extract_skills(56    file: UploadFile = File(...),57    mode: Mode = Query(58        default="gliner",59        description="GLiNER-only extraction mode for Module 1.",60    ),61):62    del mode63    try:64        data = await file.read()65        return extract_skills_from_bytes(file.filename or "", data)66    except ValueError as exc:67        raise HTTPException(status_code=400, detail=str(exc)) from exc68    except Exception as exc:69        raise HTTPException(status_code=500, detail=str(exc)) from exc70 71 72@app.post("/read-file", tags=["Inference"])73async def read_file(file: UploadFile = File(...)):74    try:75        data = await file.read()76        text = extract_text_from_upload(file.filename or "", data)77        return {"filename": file.filename, "text": text}78    except ValueError as exc:79        raise HTTPException(status_code=400, detail=str(exc)) from exc80    except Exception as exc:81        raise HTTPException(status_code=500, detail=str(exc)) from exc82 83 84@app.post("/extract-text", tags=["Inference"])85def extract_text(86    payload: TextPayload,87    mode: Mode = Query(88        default="gliner",89        description="GLiNER-only extraction mode for Module 1.",90    ),91):92    del mode93    try:94        return extract_skills_from_text(payload.text)95    except ValueError as exc:96        raise HTTPException(status_code=400, detail=str(exc)) from exc97    except Exception as exc:98        raise HTTPException(status_code=500, detail=str(exc)) from exc99