ytrsoymr commited on
Commit
f9495d8
·
verified ·
1 Parent(s): b2c7518

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +44 -29
app.py CHANGED
@@ -9,21 +9,7 @@ load_dotenv() ## Load all environment variables
9
 
10
  genai.configure(api_key=os.getenv("GOOGLE_API_KEY"))
11
 
12
- def get_gemini_response(input_text):
13
- model = genai.GenerativeModel('gemini-1.5-pro')
14
- response = model.generate_content(input_text)
15
- return response.text
16
-
17
- def input_pdf_text(uploaded_file):
18
- reader = pdf.PdfReader(uploaded_file)
19
- text = ""
20
- for page in range(len(reader.pages)):
21
- extracted_text = reader.pages[page].extract_text()
22
- if extracted_text:
23
- text += extracted_text
24
- return text
25
-
26
- # Prompt Template
27
  input_prompt = """
28
  Hey, act like a skilled and very experienced ATS (Application Tracking System)
29
  with a deep understanding of tech fields such as software engineering, data science,
@@ -37,11 +23,43 @@ and identify the missing keywords with high accuracy.
37
  resume: {text}
38
  description: {jd}
39
 
40
- I want the response in one single JSON string with the following structure:
41
- {{"JD Match":"%", "MissingKeywords":[], "Profile Summary":""}}
 
 
 
 
 
 
42
  """
43
 
44
- ## Streamlit app
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
45
  st.title("Smart ATS")
46
  st.text("Improve Your Resume for ATS Systems")
47
 
@@ -53,16 +71,13 @@ submit = st.button("Submit")
53
  if submit:
54
  if uploaded_file is not None and jd:
55
  text = input_pdf_text(uploaded_file)
56
- formatted_prompt = input_prompt.format(text=text, jd=jd)
57
- response = get_gemini_response(formatted_prompt)
58
-
59
- # Try parsing the response as JSON
60
- try:
61
- parsed_response = json.loads(response)
62
- st.subheader("Job Description Match: " + parsed_response["JD Match"])
63
- st.write("Missing Keywords: ", parsed_response["MissingKeywords"])
64
- st.write("Profile Summary: ", parsed_response["Profile Summary"])
65
- except json.JSONDecodeError:
66
- st.error("Error: Could not parse the response. Please check the response format.")
67
  else:
68
  st.warning("Please upload a resume and enter a job description.")
 
9
 
10
  genai.configure(api_key=os.getenv("GOOGLE_API_KEY"))
11
 
12
+ # Define the prompt template
 
 
 
 
 
 
 
 
 
 
 
 
 
 
13
  input_prompt = """
14
  Hey, act like a skilled and very experienced ATS (Application Tracking System)
15
  with a deep understanding of tech fields such as software engineering, data science,
 
23
  resume: {text}
24
  description: {jd}
25
 
26
+ Return ONLY a JSON response in the following format:
27
+ {{
28
+ "JD Match": "xx%",
29
+ "MissingKeywords": ["keyword1", "keyword2", ...],
30
+ "Profile Summary": "A short summary here"
31
+ }}
32
+
33
+ DO NOT include any additional text, explanation, or greetings—only return the JSON object.
34
  """
35
 
36
+ def get_gemini_response(resume_text, jd_text):
37
+ """Generates a response from Gemini API based on the resume and job description."""
38
+ formatted_prompt = input_prompt.format(text=resume_text, jd=jd_text) # Format the prompt
39
+ model = genai.GenerativeModel('gemini-1.5-pro')
40
+ response = model.generate_content(formatted_prompt)
41
+
42
+ # Ensure we get only the text response
43
+ response_text = response.text.strip()
44
+
45
+ # Attempt to extract JSON from the response
46
+ try:
47
+ parsed_response = json.loads(response_text)
48
+ return parsed_response # Return parsed JSON
49
+ except json.JSONDecodeError:
50
+ return None # Return None if response is not valid JSON
51
+
52
+ def input_pdf_text(uploaded_file):
53
+ """Extracts text from the uploaded PDF resume."""
54
+ reader = pdf.PdfReader(uploaded_file)
55
+ text = ""
56
+ for page in range(len(reader.pages)):
57
+ extracted_text = reader.pages[page].extract_text()
58
+ if extracted_text:
59
+ text += extracted_text
60
+ return text
61
+
62
+ # Streamlit app
63
  st.title("Smart ATS")
64
  st.text("Improve Your Resume for ATS Systems")
65
 
 
71
  if submit:
72
  if uploaded_file is not None and jd:
73
  text = input_pdf_text(uploaded_file)
74
+ response = get_gemini_response(text, jd) # Pass formatted resume & JD
75
+
76
+ if response:
77
+ st.subheader(f"Job Description Match: {response['JD Match']}")
78
+ st.write("Missing Keywords: ", response["MissingKeywords"])
79
+ st.write("Profile Summary: ", response["Profile Summary"])
80
+ else:
81
+ st.error("Error: Gemini did not return valid JSON. Please try again.")
 
 
 
82
  else:
83
  st.warning("Please upload a resume and enter a job description.")