honeyangelhp commited on
Commit
afbdb1b
·
verified ·
1 Parent(s): 83ee5c0

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +129 -66
app.py CHANGED
@@ -1,72 +1,135 @@
1
- from sklearn.feature_extraction.text import TfidfVectorizer
2
- from sklearn.metrics.pairwise import cosine_similarity
3
  import streamlit as st
4
- import nltk
5
- from nltk.tokenize import sent_tokenize
6
-
7
- # Download NLTK tokenizer data
8
- nltk.download("punkt", quiet=True)
9
-
10
- # Helper Function: Calculate ATS Score for Multiple Resumes
11
- def calculateATSscores(resumes, job_description):
12
- vectorizer = TfidfVectorizer(stop_words="english")
13
- all_text = [job_description] + resumes
14
- tfidf_matrix = vectorizer.fit_transform(all_text)
15
- similarity_scores = cosine_similarity(tfidf_matrix[0:1], tfidf_matrix[1:]).flatten()
16
- return similarity_scores
17
-
18
- # Helper Function: Summarize Resume
19
- def summarizeResume(resume, job_description, n_sentences=3):
20
- sentences = sent_tokenize(resume)
21
- all_text = [job_description] + sentences
22
- vectorizer = TfidfVectorizer(stop_words="english")
23
- tfidf_matrix = vectorizer.fit_transform(all_text)
24
- similarity_scores = cosine_similarity(tfidf_matrix[0:1], tfidf_matrix[1:]).flatten()
25
- top_indices = similarity_scores.argsort()[-n_sentences:][::-1]
26
- top_sentences = [sentences[i] for i in top_indices]
27
- summary = " ".join(top_sentences)
28
- return summary
29
-
30
- # Streamlit App
31
- st.title("AI-Powered ATS Screening Tool")
32
-
33
- # Step 1: Upload Multiple Resumes
34
- st.header("Step 1: Upload Resumes")
35
- uploaded_files = st.file_uploader("Upload your resumes (PDFs only):", type="pdf", accept_multiple_files=True)
36
-
37
- resumes = []
38
- if uploaded_files:
39
- from convert import ExtractPDFText # Assuming this module extracts text from PDFs
40
- for file in uploaded_files:
41
- extracted_text = ExtractPDFText(file)
42
- resumes.append(extracted_text)
43
- st.success(f"{len(resumes)} resumes uploaded successfully.")
44
-
45
- # Step 2: Input Job Description
46
- st.header("Step 2: Input Job Description")
47
- job_description = st.text_area("Paste the job description below:")
48
- st.info("You can copy-paste directly from the job portal.")
49
-
50
- # Step 3: Analyze and Display Results
51
- if resumes and job_description and st.button("Analyze Resumes"):
52
- with st.spinner("Analyzing resumes..."):
53
- # Calculate similarity scores
54
- ats_scores = calculateATSscores(resumes, job_description)
55
 
56
- # Rank resumes by similarity
57
- ranked_resumes = sorted(zip(resumes, ats_scores), key=lambda x: x[1], reverse=True)
 
 
 
58
 
59
- st.subheader("Results: Resumes Ranked by Similarity")
 
60
 
61
- for rank, (resume_text, score) in enumerate(ranked_resumes, start=1):
62
- st.markdown(f"### Rank {rank}: Similarity Score = {score:.2f}")
63
-
64
- # Summarize each resume
65
- summary = summarizeResume(resume_text, job_description)
66
-
67
- st.write("*Summary of Resume:*")
68
- st.write(summary)
69
- st.write("---")
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
70
 
 
 
 
71
  else:
72
- st.warning("Please upload resumes and input a job description to proceed.")
 
1
+ import fitz
2
+ from io import BytesIO
3
  import streamlit as st
4
+
5
+ from sklearn.feature_extraction.text import TfidfVectorizer
6
+ from sklearn.metrics.pairwise import cosine_similarity
7
+ from sklearn.feature_extraction import _stop_words
8
+ from convert import ExtractPDFText
9
+
10
+ def ExtractPDFText(pdf):
11
+ content = ""
12
+ pdf_bytes = pdf.read()
13
+
14
+ try:
15
+ pdf_document = fitz.open("dummy.pdf", pdf_bytes)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
16
 
17
+ # Iterate through pages and extract text
18
+ for page_number in range(pdf_document.page_count):
19
+ page = pdf_document[page_number]
20
+ text = page.get_text()
21
+ content += text
22
 
23
+ except Exception as e:
24
+ st.error(f"Error extracting text from PDF: {e}")
25
 
26
+ finally:
27
+ if "pdf_document" in locals():
28
+ pdf_document.close()
29
+
30
+ return content
31
+
32
+ #find ats score
33
+ def calculateATSscore(resume_data, job_description):
34
+ stopwords = list(_stop_words.ENGLISH_STOP_WORDS)
35
+ vectorizer = TfidfVectorizer(stop_words=stopwords)
36
+ vectors = vectorizer.fit_transform([job_description, resume_data])
37
+ similarity_value = cosine_similarity(vectors)
38
+ print(similarity_value)
39
+ # return similarity_value[0,1]
40
+ return similarity_value[0,1]
41
+
42
+
43
+ import google.generativeai as genai
44
+ import os
45
+ from dotenv import load_dotenv
46
+ load_dotenv()
47
+
48
+ genai.configure(api_key = os.environ["GOOGLE_API_KEY"])
49
+
50
+ model = genai.GenerativeModel("gemini-pro")
51
+
52
+ def modelFeedback(ats_score,resume_data):
53
+
54
+ input_prompt = f"""
55
+ You are now an ATS Score analyzer and given ATS Score is {int(ats_score*100)}%.
56
+ Your task is to provide feedback to the user based on the ATS score.
57
+ print ATS score first. mention where resume is good and where resume lacks.
58
+ talk about each section of user's resume and talk good and bad points of it.
59
+ """
60
+ response = model.generate_content([input_prompt,resume_data],stream=True)
61
+ response.resolve()
62
+
63
+ return response
64
+
65
+
66
+ # Import necessary libraries
67
+ import time
68
+
69
+
70
+ if "page_number" not in st.session_state:
71
+ st.session_state.page_number = 1
72
+
73
+ if "resume_data" not in st.session_state:
74
+ st.session_state.resume_data = ""
75
+
76
+ if "jobdescription" not in st.session_state:
77
+ st.session_state.jobdescription = ""
78
+
79
+ def set_page_number_and_reset_data():
80
+ st.session_state.page_number = 1
81
+ st.session_state.resume_data = ""
82
+
83
+
84
+ def page1():
85
+ st.title("AI-Powered ATS Screening")
86
+ if not st.session_state.resume_data:
87
+ pdf = st.file_uploader(label="Upload your resume", type="pdf")
88
+ st.write("No Resume Yet? Create one [here](https://www.overleaf.com/latex/templates/tagged/cv)")
89
+
90
+ if pdf:
91
+ st.success("Resume uploaded successfully.")
92
+ st.session_state.resume_data = ExtractPDFText(pdf)
93
+
94
+ def page2():
95
+ st.title("AI-Powered ATS Screening: Job Description")
96
+ st.session_state.jobdescription = st.text_area("Job Description: ")
97
+ st.info("You can just copy paste from the job portal")
98
+ submit = st.button("Submit")
99
+
100
+ if submit:
101
+ start()
102
+
103
+ def page3():
104
+ st.title("Your Resume data: ")
105
+ if st.session_state.resume_data:
106
+ st.write(st.session_state.resume_data)
107
+ else:
108
+ st.error("Please upload your resume to view the extracted data")
109
+
110
+ def start():
111
+ if st.session_state.resume_data and st.session_state.jobdescription:
112
+ with st.spinner("Hold on, we're calculating your ATS Score..."):
113
+ ATS_score = calculateATSscore(st.session_state.resume_data, st.session_state.jobdescription)
114
+ model_feedback = modelFeedback(ATS_score, st.session_state.resume_data)
115
+ # time.sleep(5)
116
+
117
+
118
+ st.subheader("AI FEEDBACK:")
119
+ st.write(model_feedback.text)
120
+
121
+ else:
122
+ st.info("Please, upload Resume and Provide the Job Description")
123
+
124
+ if st.session_state.page_number == 1:
125
+ page1()
126
+ elif st.session_state.page_number == 2:
127
+ page2()
128
+ elif st.session_state.page_number == 3:
129
+ page3()
130
 
131
+ if st.session_state.page_number == 1:
132
+ st.button("View your Extracted Resume data", on_click = lambda: setattr(st.session_state,"page_number", 3))
133
+ st.button("Go to Job Description Page", on_click=lambda: setattr(st.session_state, "page_number", 2))
134
  else:
135
+ st.button("Go to PDF Upload Page", on_click=lambda: set_page_number_and_reset_data())