Spaces:
Sleeping
Sleeping
File size: 3,539 Bytes
99bbd64 8683e61 99bbd64 89ac774 8683e61 99bbd64 89509c4 99bbd64 7dbf682 9e0b38e 99bbd64 9e0b38e 7dbf682 6e78f7b fa24c7d 4aba3cf bcc36a0 4d13280 bcc36a0 24a440f 4696f89 8683e61 4696f89 fa24c7d 9e0b38e fa24c7d 24a440f 194b1f0 fa24c7d 6e78f7b 89ac774 a587148 89509c4 fa24c7d 2e32f9d 7b15466 71694b0 9597d26 0d1fe0d 7b15466 0d1fe0d 2e32f9d 9e0b38e d21275b 8683e61 1e4a1c0 621b61f bc7a2c2 02cf2aa bc7a2c2 02cf2aa bc7a2c2 02cf2aa bc7a2c2 |
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 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 |
#Fast APi Packages
from fastapi import FastAPI,File, UploadFile
from pydantic import BaseModel
import json
from typing_extensions import Annotated
#SkillExtraction Packages
from PyPDF2 import PdfReader
import psycopg2
from psycopg2 import sql
import pandas as pd
from datetime import date
import numpy as np
import spacy
import re
from sentence_transformers import SentenceTransformer, util
from sklearn.feature_extraction.text import CountVectorizer
from sklearn.metrics.pairwise import cosine_similarity
from io import StringIO
from spacy.matcher import PhraseMatcher
from skillNer.general_params import SKILL_DB
from skillNer.skill_extractor_class import SkillExtractor
from psycopg2.extensions import register_adapter, AsIs
register_adapter(np.int64, AsIs)
import warnings
warnings.filterwarnings('ignore')
#Custom Classes for endpoints
from DbConnection import DbConnection
from UploadFile import UploadOpenFile
from SkillExtract import SkillExtractorDetails
import os
os.environ['HF_HOME'] = '/hug/cache/'
app = FastAPI()
class FileDetails(BaseModel):
filecontents: str
filename: str
fileid: str
message: str
class SkillDetails(BaseModel):
skillid: int
requiredSkills: str
softSkills: str
goodToHaveSkills: str
class FileResponse(BaseModel):
fileid: int
message: str
nlp = spacy.load("en_core_web_lg")
# init skill extractor
skill_extractor = SkillExtractor(nlp, SKILL_DB, PhraseMatcher)
@app.get("/")
async def root():
return {"SkillAPI":"SkillAPi Version 0.05"}
#https://vaibhav84-resumeapi.hf.space/docs
db_params = DbConnection.GetDbConnection()
def parse_csv(df):
res = df.to_json(orient="records")
parsed = json.loads(res)
return parsed
@app.get("/ProfileMatch")
def ProfileMatchResults():
dbQuery = "select * from profilematch"
conn = psycopg2.connect(**db_params)
df = pd.read_sql_query(dbQuery, conn)
return parse_csv(df)
@app.post("/UploadFile/")
def UploadFileDetails(file_data: FileDetails):
returnID = UploadOpenFile.uploadFile(file_data.filecontents,file_data.filename,db_params)
file_data.filecontents = ""
file_data.fileid = str(returnID)
file_data.message = "File Uploaded Successfully!"
return file_data
@app.post("/ExtractSkills/")
def ExtractSkills(skill_data: SkillDetails):
returnSkills = SkillExtractorDetails.SkillExtract(db_params,skill_extractor,skill_data.skillid)
details = returnSkills.split('@')
skill_data.requiredSkills = details[0]
skill_data.softSkills = details[1]
skill_data.goodToHaveSkills = details[1]
return skill_data
@app.post("/uploadJobDescription/")
def create_upload_file(file: bytes = File(...)):
content = file.decode('utf-8')
lines = content.split('\n')
return {"content": lines}
@app.post("/uploadJobDescriptionPDF/")
def upload_PDF(file: UploadFile = File(...)):
try:
contents = file.file.read()
with open(file.filename, 'wb') as f:
f.write(contents)
except Exception:
return {"message": "There was an error uploading the file"}
finally:
file.file.close()
return {"message": f"Successfully uploaded {contents}"}
@app.post("/uploadJobDescriptionPDF2/")
def upload_PDF2(file: UploadFile = File(...)):
text =''
if file.filename.endswith("pdf"):
pdf_reader = PdfReader(file)
for page in pdf_reader.pages:
text += page.extract_text()
return {"message": f"Successfully uploaded {text}"} |