pktpaulie commited on
Commit
1423a16
·
verified ·
1 Parent(s): 7fe1010

Refactor into helper functions

Browse files
Files changed (1) hide show
  1. app.py +41 -29
app.py CHANGED
@@ -87,6 +87,37 @@ with col1:
87
  with col2:
88
  uploaded_job_description = st.file_uploader("Upload Job Description (.docx or .pdf)", type=["docx", "pdf"], key="job_description")
89
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
90
  # Process if files are uploaded
91
  if uploaded_resume and uploaded_job_description:
92
  # Save files
@@ -99,32 +130,9 @@ if uploaded_resume and uploaded_job_description:
99
 
100
  if st.button("Resume-JD Matching"):
101
  with st.spinner("Computing Match"):
102
- similarity_score = similarity_main(resume_path, job_description_path)
103
- if isinstance(similarity_score, str) and '%' in similarity_score:
104
- similarity_score = float(similarity_score.replace('%', ''))
105
-
106
- # Display messages based on score range
107
- if similarity_score < 50:
108
- st.markdown('<p style="color: red; font-weight: bold;">Low chance, skills gap identified!</p>', unsafe_allow_html=True)
109
- pie_colors = ['#FF4B4B', '#E5E5E5']
110
- elif 50 <= similarity_score < 70:
111
- st.markdown('<p style="color: red; font-weight: bold;">Good chance but you can improve further!</p>')
112
- pie_colors = ['#FFC107', '#E5E5E5']
113
- else:
114
- st.markdown('<p style="color: green; font-weight: bold;">Excellent! You can submit your CV.</p>', unsafe_allow_html=True)
115
- pie_colors = ['#4CAF50', '#E5E5E5']
116
-
117
- # Display Score as a Pie Chart
118
- st.markdown(f"### Similarity Score: {int(similarity_score)}%")
119
 
120
- # Pie chart to show similarity
121
- fig, ax = plt.subplots()
122
- # ax.pie([similarity_score, 100 - similarity_score], labels=['Match', 'Difference'], autopct='%1.1f%%', startangle=140, colors=['#4B7BE5', '#E5E5E5'])
123
- ax.pie([similarity_score, 100 - similarity_score], labels=['Match', 'Difference'], autopct='%1.1f%%', startangle=140, colors=pie_colors)
124
-
125
- ax.axis('equal')
126
- st.pyplot(fig)
127
-
128
  #Autoscroll
129
  st.markdown("""
130
  <script>
@@ -138,8 +146,8 @@ if uploaded_resume and uploaded_job_description:
138
 
139
  if st.button("Tailor Resume"):
140
  with st.spinner("Generating resume..."):
141
- generated_resume = generate_gemini(resume_path, job_description_path)
142
- st.subheader("Generated Tailored Resume:")
143
  # st.write(generated_resume)
144
 
145
  #Autoscroll
@@ -148,7 +156,11 @@ if uploaded_resume and uploaded_job_description:
148
  window.scrollTo(0, document.body.scrollHeight);
149
  </script>
150
  """, unsafe_allow_html=True)
151
-
 
 
 
 
152
  if generated_resume is not None:
153
  from io import BytesIO
154
  from docx import Document
@@ -166,7 +178,7 @@ if uploaded_resume and uploaded_job_description:
166
  file_name="tailored_resume.docx",
167
  mime="application/vnd.openxmlformats-officedocument.wordprocessingml.document"
168
  )
169
-
170
 
171
  else:
172
  st.warning("Please upload both the resume and job description files.")
 
87
  with col2:
88
  uploaded_job_description = st.file_uploader("Upload Job Description (.docx or .pdf)", type=["docx", "pdf"], key="job_description")
89
 
90
+ def get_score(resume_path, job_description_path):
91
+ similarity_score = similarity_main(resume_path, job_description_path)
92
+ if isinstance(similarity_score, str) and '%' in similarity_score:
93
+ similarity_score = float(similarity_score.replace('%', ''))
94
+
95
+ # Display messages based on score range
96
+ if similarity_score < 50:
97
+ st.markdown('<p style="color: red; font-weight: bold;">Low chance, skills gap identified!</p>', unsafe_allow_html=True)
98
+ pie_colors = ['#FF4B4B', '#E5E5E5']
99
+ elif 50 <= similarity_score < 70:
100
+ st.markdown('<p style="color: red; font-weight: bold;">Good chance but you can improve further!</p>')
101
+ pie_colors = ['#FFC107', '#E5E5E5']
102
+ else:
103
+ st.markdown('<p style="color: green; font-weight: bold;">Excellent! You can submit your CV.</p>', unsafe_allow_html=True)
104
+ pie_colors = ['#4CAF50', '#E5E5E5']
105
+
106
+ return similarity_score
107
+
108
+ def display_score(similarity):
109
+ # Display Score as a Pie Chart
110
+ st.markdown(f"### Similarity Score: {int(similarity_score)}%")
111
+
112
+ # Pie chart to show similarity
113
+ fig, ax = plt.subplots()
114
+ # ax.pie([similarity_score, 100 - similarity_score], labels=['Match', 'Difference'], autopct='%1.1f%%', startangle=140, colors=['#4B7BE5', '#E5E5E5'])
115
+ ax.pie([similarity_score, 100 - similarity_score], labels=['Match', 'Difference'], autopct='%1.1f%%', startangle=140, colors=pie_colors)
116
+
117
+ ax.axis('equal')
118
+ st.pyplot(fig)
119
+
120
+
121
  # Process if files are uploaded
122
  if uploaded_resume and uploaded_job_description:
123
  # Save files
 
130
 
131
  if st.button("Resume-JD Matching"):
132
  with st.spinner("Computing Match"):
133
+ score = get_score(resume_path, job_description_path)
134
+ display_score(score)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
135
 
 
 
 
 
 
 
 
 
136
  #Autoscroll
137
  st.markdown("""
138
  <script>
 
146
 
147
  if st.button("Tailor Resume"):
148
  with st.spinner("Generating resume..."):
149
+ generated_resume, new_resume_path = generate_gemini(resume_path, job_description_path)
150
+ st.markdown("Generated Tailored Resume:")
151
  # st.write(generated_resume)
152
 
153
  #Autoscroll
 
156
  window.scrollTo(0, document.body.scrollHeight);
157
  </script>
158
  """, unsafe_allow_html=True)
159
+
160
+ with st.spinner("Computing Match"):
161
+ score = get_score(new_resume_path, job_description_path)
162
+ display_score(score)
163
+
164
  if generated_resume is not None:
165
  from io import BytesIO
166
  from docx import Document
 
178
  file_name="tailored_resume.docx",
179
  mime="application/vnd.openxmlformats-officedocument.wordprocessingml.document"
180
  )
181
+
182
 
183
  else:
184
  st.warning("Please upload both the resume and job description files.")