Spaces:
Running
Running
Create main.py
Browse files
main.py
ADDED
@@ -0,0 +1,53 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import google.generativeai as genai
|
2 |
+
import os
|
3 |
+
import PyPDF2 as pdf
|
4 |
+
import json
|
5 |
+
from fastapi import FastAPI, Request, UploadFile, File
|
6 |
+
app = FastAPI()
|
7 |
+
#Prompt Template
|
8 |
+
|
9 |
+
input_prompt="""
|
10 |
+
Hey Act Like a skilled or very experience ATS(Application Tracking System)
|
11 |
+
with a deep understanding of tech field,software engineering,data science ,data analyst
|
12 |
+
and big data engineer. Your task is to evaluate the resume based on the given job description.
|
13 |
+
You must consider the job market is very competitive and you should provide
|
14 |
+
best assistance for improving thr resumes. Assign the percentage Matching based
|
15 |
+
on Jd and
|
16 |
+
the missing keywords with high accuracy
|
17 |
+
resume:{text}
|
18 |
+
description:{jd}
|
19 |
+
I want the response as per below structure
|
20 |
+
{{"JD Match": "%", "MissingKeywords": [], "Profile Summary": ""}}
|
21 |
+
"""
|
22 |
+
genai.configure(api_key=os.environ.get("API_TOKEN"))
|
23 |
+
|
24 |
+
def get_gemini_repsonse(input):
|
25 |
+
model=genai.GenerativeModel('gemini-pro')
|
26 |
+
response=model.generate_content(input)
|
27 |
+
return response.text
|
28 |
+
|
29 |
+
def input_pdf_text(uploaded_file):
|
30 |
+
reader=pdf.PdfReader(uploaded_file)
|
31 |
+
text=""
|
32 |
+
for page in range(len(reader.pages)):
|
33 |
+
page=reader.pages[page]
|
34 |
+
text+=str(page.extract_text())
|
35 |
+
return text
|
36 |
+
|
37 |
+
|
38 |
+
@app.post("/resume_parser/")
|
39 |
+
async def process_pdf_file(file: UploadFile = File(...)):
|
40 |
+
contents = await file.read()
|
41 |
+
with open(file.filename, 'wb') as f:
|
42 |
+
f.write(contents)
|
43 |
+
|
44 |
+
return await process_pdf(file.filename)
|
45 |
+
|
46 |
+
async def process_pdf(pdf_source):
|
47 |
+
|
48 |
+
text=input_pdf_text(pdf_source)
|
49 |
+
response=get_gemini_repsonse(input_prompt)
|
50 |
+
return response
|
51 |
+
|
52 |
+
|
53 |
+
|