avizard commited on
Commit
a79d5c0
1 Parent(s): d185476

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +52 -61
app.py CHANGED
@@ -1,42 +1,49 @@
1
  import os
2
- import io
3
  import streamlit as st
4
  from dotenv import load_dotenv
5
- import fitz # PyMuPDF
6
- import base64
7
- import google.generativeai as genai
8
 
9
-
10
- # Load environment variables
11
  load_dotenv()
 
12
 
13
- # Configure your application, for example, with an API key for a service
14
- # api_key = os.getenv("API_KEY")
15
-
16
- def get_gemini_response(input, pdf_content,prompt):
17
- model = genai.GenerativeModel('gemini-pro')
18
- response = model.generate_content([input,pdf_content[0],prompt])
19
- return response.text
20
-
21
- def extract_text_from_first_page(pdf_path):
22
- """Extract text from the first page of a PDF file using PyMuPDF (fitz)."""
23
- doc = fitz.open(pdf_path)
24
- first_page_text = doc[0].get_text()
25
  doc.close()
26
- return first_page_text
27
 
28
- def input_pdf_setup(upload_file):
29
- """Save uploaded file to disk and extract text from the first page."""
30
- if upload_file is not None:
31
- # Save the uploaded PDF to a temporary file
32
- with open("temp_uploaded.pdf", "wb") as f:
33
- f.write(upload_file.getbuffer())
34
-
35
- # Extract text from the first page
36
- extracted_text = extract_text_from_first_page("temp_uploaded.pdf")
37
- return extracted_text
38
- else:
39
- raise FileNotFoundError("No File uploaded")
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
40
 
41
  # Streamlit UI setup
42
  st.set_page_config(page_title="Resume Parser")
@@ -49,36 +56,20 @@ uploaded_file = st.file_uploader("Upload your resume (only PDFs are supported)..
49
  if uploaded_file is not None:
50
  st.write("Resume uploaded successfully.")
51
 
52
- submit1=st.button("Tell me about the resume")
53
-
54
- submit2=st.button("Percentage match with the job description")
55
 
56
- input_prompt1 = """
57
- You are an experienced Technical Human Resource Manager,your task is to review the provided resume against the job description.
58
- Please share your professional evaluation on whether the candidate's profile aligns with the role.
59
- Highlight the strengths and weaknesses of the applicant in relation to the specified job requirements.
60
- """
61
-
62
- input_prompt2 = """
63
- You are an skilled ATS (Applicant Tracking System) scanner with a deep understanding of data science and ATS functionality,
64
- your task is to evaluate the resume against the provided job description. give me the percentage of match if the resume matches
65
- the job description. First the output should come as a percentage and then keywords missing and last final thoughts.
66
- """
67
-
68
- if submit1:
69
- if uploaded_file is not None:
70
- pdf_content=input_pdf_setup(uploaded_file)
71
- response=get_gemini_response(input_prompt1,pdf_content,input_text)
72
- st.subheader("The Response is")
73
  st.write(response)
74
- else:
75
- st.write("Please upload the resume")
76
-
77
- elif submit2:
78
- if uploaded_file is not None:
79
- pdf_content=input_pdf_setup(uploaded_file)
80
- response=get_gemini_response(input_prompt2,pdf_content,input_text)
81
- st.subheader("The Response is")
82
  st.write(response)
83
- else:
84
- st.write("Please upload the resume")
 
 
1
  import os
 
2
  import streamlit as st
3
  from dotenv import load_dotenv
4
+ import fitz # PyMuPDF for handling PDFs
5
+ import openai
 
6
 
7
+ # Load environment variables and configure OpenAI API key
 
8
  load_dotenv()
9
+ openai.api_key = os.getenv("OPENAI_API_KEY")
10
 
11
+ def extract_text_from_pdf(upload_file):
12
+ """Extract text from a PDF file using PyMuPDF (fitz)."""
13
+ doc = fitz.open(stream=upload_file.read(), filetype="pdf")
14
+ text = ""
15
+ for page in doc:
16
+ text += page.get_text("text")
 
 
 
 
 
 
17
  doc.close()
18
+ return text
19
 
20
+ def get_openai_response(job_description, resume_text, prompt_type):
21
+ """Send a prompt to the OpenAI API including both job description and resume text, and return the response."""
22
+ if prompt_type == "evaluation":
23
+ prompt = f"""
24
+ As an experienced Technical Human Resource Manager, evaluate the following resume against the job description provided:
25
+ Job Description: {job_description}
26
+ Resume Text: {resume_text}
27
+ Based on the job description and resume, provide a professional evaluation on whether the candidate's profile aligns with the role, highlighting the strengths and weaknesses.
28
+ """
29
+ elif prompt_type == "match_percentage":
30
+ prompt = f"""
31
+ As a skilled ATS scanner with a deep understanding of data science and ATS functionality, evaluate how well the following resume matches the job description provided:
32
+ Job Description: {job_description}
33
+ Resume Text: {resume_text}
34
+ Estimate the percentage match and list any missing keywords or qualifications.
35
+ """
36
+
37
+ response = openai.Completion.create(
38
+ engine="gpt-3.5-turbo-instruct", # Adjust as necessary
39
+ prompt=prompt,
40
+ temperature=0.7,
41
+ max_tokens=1024, # Adjusted to allow for more detailed responses
42
+ top_p=1.0,
43
+ frequency_penalty=0.0,
44
+ presence_penalty=0.0
45
+ )
46
+ return response.choices[0].text.strip()
47
 
48
  # Streamlit UI setup
49
  st.set_page_config(page_title="Resume Parser")
 
56
  if uploaded_file is not None:
57
  st.write("Resume uploaded successfully.")
58
 
59
+ submit1 = st.button("Tell me about the resume")
60
+ submit2 = st.button("Percentage match with the job description")
 
61
 
62
+ if uploaded_file is not None:
63
+ resume_text = extract_text_from_pdf(uploaded_file)
64
+
65
+ if submit1:
66
+ response = get_openai_response(input_text, resume_text, "evaluation")
67
+ st.subheader("The Response is:")
 
 
 
 
 
 
 
 
 
 
 
68
  st.write(response)
69
+ elif submit2:
70
+ response = get_openai_response(input_text, resume_text, "match_percentage")
71
+ st.subheader("The Response is:")
 
 
 
 
 
72
  st.write(response)
73
+ else:
74
+ if submit1 or submit2:
75
+ st.error("Please upload the resume.")