nlpblogs commited on
Commit
63bbd4e
·
verified ·
1 Parent(s): 4fae0db

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +33 -68
app.py CHANGED
@@ -40,96 +40,61 @@ with st.sidebar:
40
  ''')
41
 
42
 
 
43
  st.title("AI Resume Analysis based on Keywords App")
44
  st.divider()
45
 
46
- st.subheader("Job Description", divider="red")
47
- txt = st.text_area("Paste the job description and then press Ctrl + Enter", key="text 1")
48
- job = pd.Series(txt, name="Text")
49
 
50
- st.subheader("Applicant Resume 1", divider="green")
51
- if 'upload_count' not in st.session_state:
52
- st.session_state['upload_count'] = 0
53
 
54
  max_attempts = 20
55
- if st.session_state['upload_count'] < max_attempts:
56
- uploaded_files = st.file_uploader("Upload Applicant's 1 resume", type="pdf", key="candidate 1")
57
- if uploaded_files:
58
- st.session_state['upload_count'] += 1
59
-
60
- pdf_reader = PdfReader(uploaded_files)
61
- text_data = ""
62
- for page in pdf_reader.pages:
63
- text_data += page.extract_text()
64
- with st.expander("See Applicant'1 resume"):
65
- st.write(text_data)
66
-
67
- data = pd.Series(text_data, name='Text')
68
- frames = [job, data]
69
- result = pd.concat(frames)
70
-
71
-
72
- vectorizer = TfidfVectorizer()
73
- tfidf_matrix = vectorizer.fit_transform(result)
74
- tfidf_df = pd.DataFrame(tfidf_matrix.toarray(), columns=vectorizer.get_feature_names_out())
75
- cosine_sim_matrix = cosine_similarity(tfidf_matrix)
76
- cosine_sim_df = pd.DataFrame(cosine_sim_matrix)
77
-
78
- for i, similarity_score in enumerate(cosine_sim_matrix[0][1:]):
79
- with st.popover("See result"):
80
- st.write(f"Similarity of job description with Applicant's 1 resume based on keywords: {similarity_score:.2f}")
81
- st.info(
82
- "A score closer to 1 (0.80, 0.90) means higher similarity between Applicant's 1 resume and job description. A score closer to 0 (0.20, 0.30) means lower similarity between Applicant's 1 resume and job description.")
83
- else:
84
- st.warning(f"You have reached the maximum upload attempts ({max_attempts}).")
85
- if 'upload_count' in st.session_state and st.session_state['upload_count'] > 0:
86
- st.info(f"Files uploaded {st.session_state['upload_count']} time(s).")
87
 
 
 
 
 
88
 
 
 
89
 
 
 
90
 
91
- st.subheader("Job Description", divider="red")
92
- txt = st.text_area("Paste the job description and then press Ctrl + Enter", key="text 2")
93
- job = pd.Series(txt, name="Text")
 
94
 
95
- st.subheader("Applicant Resume 2", divider="green")
96
- if 'upload_count' not in st.session_state:
97
- st.session_state['upload_count'] = 0
 
 
98
 
99
- max_attempts = 20
100
- if st.session_state['upload_count'] < max_attempts:
101
- uploaded_files = st.file_uploader("Upload Applicant's 2 resume", type="pdf", key="candidate 2")
102
- if uploaded_files:
103
- st.session_state['upload_count'] += 1
104
-
105
- pdf_reader = PdfReader(uploaded_files)
106
- text_data = ""
107
- for page in pdf_reader.pages:
108
- text_data += page.extract_text()
109
- with st.expander("See Applicant'2 resume"):
110
  st.write(text_data)
111
-
112
  data = pd.Series(text_data, name='Text')
113
- frames = [job, data]
114
- result = pd.concat(frames)
115
-
116
 
117
  vectorizer = TfidfVectorizer()
118
  tfidf_matrix = vectorizer.fit_transform(result)
119
- tfidf_df = pd.DataFrame(tfidf_matrix.toarray(), columns=vectorizer.get_feature_names_out())
120
  cosine_sim_matrix = cosine_similarity(tfidf_matrix)
121
- cosine_sim_df = pd.DataFrame(cosine_sim_matrix)
122
 
123
- for i, similarity_score in enumerate(cosine_sim_matrix[0][1:]):
 
124
  with st.popover("See result"):
125
- st.write(f"Similarity of job description with Applicant's 2 resume based on keywords: {similarity_score:.2f}")
126
  st.info(
127
- "A score closer to 1 (0.80, 0.90) means higher similarity between Applicant's 2 resume and job description. A score closer to 0 (0.20, 0.30) means lower similarity between Applicant's 2 resume and job description.")
128
- else:
129
- st.warning(f"You have reached the maximum upload attempts ({max_attempts}).")
130
- if 'upload_count' in st.session_state and st.session_state['upload_count'] > 0:
131
- st.info(f"Files uploaded {st.session_state['upload_count']} time(s).")
132
 
 
 
 
 
133
 
134
 
135
 
 
40
  ''')
41
 
42
 
43
+
44
  st.title("AI Resume Analysis based on Keywords App")
45
  st.divider()
46
 
47
+ job = pd.Series(st.text_area("Paste the job description and then press Ctrl + Enter", key="job_desc"), name="Text")
 
 
48
 
49
+ if 'applicant_data' not in st.session_state:
50
+ st.session_state['applicant_data'] = {}
 
51
 
52
  max_attempts = 20
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
53
 
54
+ for i in range(1, 3): # Looping for 2 applicants
55
+ st.subheader(f"Applicant Resume {i}", divider="green")
56
+ applicant_key = f"applicant_{i}"
57
+ upload_key = f"candidate_{i}"
58
 
59
+ if applicant_key not in st.session_state['applicant_data']:
60
+ st.session_state['applicant_data'][applicant_key] = {'upload_count': 0, 'uploaded_file': None, 'analysis_done': False}
61
 
62
+ if st.session_state['applicant_data'][applicant_key]['upload_count'] < max_attempts:
63
+ uploaded_file = st.file_uploader(f"Upload Applicant's {i} resume", type="pdf", key=upload_key)
64
 
65
+ if uploaded_file:
66
+ st.session_state['applicant_data'][applicant_key]['uploaded_file'] = uploaded_file
67
+ st.session_state['applicant_data'][applicant_key]['upload_count'] += 1
68
+ st.session_state['applicant_data'][applicant_key]['analysis_done'] = False # Reset analysis flag
69
 
70
+ if st.session_state['applicant_data'][applicant_key]['uploaded_file'] and not st.session_state['applicant_data'][applicant_key]['analysis_done']:
71
+ pdf_reader = PdfReader(st.session_state['applicant_data'][applicant_key]['uploaded_file'])
72
+ text_data = ""
73
+ for page in pdf_reader.pages:
74
+ text_data += page.extract_text()
75
 
76
+ with st.expander(f"See Applicant's {i} resume"):
 
 
 
 
 
 
 
 
 
 
77
  st.write(text_data)
78
+
79
  data = pd.Series(text_data, name='Text')
80
+ result = pd.concat([job, data])
 
 
81
 
82
  vectorizer = TfidfVectorizer()
83
  tfidf_matrix = vectorizer.fit_transform(result)
 
84
  cosine_sim_matrix = cosine_similarity(tfidf_matrix)
 
85
 
86
+ st.subheader(f"Similarity Analysis for Applicant {i}")
87
+ for j, similarity_score in enumerate(cosine_sim_matrix[0][1:]):
88
  with st.popover("See result"):
89
+ st.write(f"Similarity based on keyword: {similarity_score:.2f}")
90
  st.info(
91
+ f"A score closer to 1 means higher similarity between Applicant's {i} resume and job description.")
92
+ st.session_state['applicant_data'][applicant_key]['analysis_done'] = True
 
 
 
93
 
94
+ else:
95
+ st.warning(f"Applicant {i} has reached the maximum upload attempts ({max_attempts}).")
96
+ if st.session_state['applicant_data'][applicant_key]['upload_count'] > 0:
97
+ st.info(f"Files uploaded for Applicant {i}: {st.session_state['applicant_data'][applicant_key]['upload_count']} time(s).")
98
 
99
 
100