Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -153,6 +153,19 @@ def display_score(similarity, colors):
|
|
153 |
ax.axis('equal')
|
154 |
st.pyplot(fig)
|
155 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
156 |
def save_docx_as_pdf(doc_content, output_path='output.pdf'):
|
157 |
# Save document content as a .docx file
|
158 |
temp_doc_path = 'temp.docx'
|
@@ -167,11 +180,27 @@ def save_docx_as_pdf(doc_content, output_path='output.pdf'):
|
|
167 |
|
168 |
# subprocess.run(['libreoffice', '--headless', '--convert-to', 'pdf', temp_doc_path, '--outdir', os.path.dirname(output_path)])
|
169 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
170 |
# if uploaded_resume.type == "application/vnd.openxmlformats-officedocument.wordprocessingml.document":
|
171 |
# save_docx_as_pdf(resume_path, 'uploaded_resume.pdf')
|
172 |
# display_doc_as_image('uploaded_resume.pdf')
|
173 |
|
174 |
def display_doc_as_image(pdf_path):
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
175 |
# poppler_path = 'usr/bin'
|
176 |
# images = convert_from_path(pdf_path, poppler_path=poppler_path)
|
177 |
# for img in images:
|
@@ -225,7 +254,7 @@ if uploaded_resume and uploaded_job_description:
|
|
225 |
</script>
|
226 |
""", unsafe_allow_html=True)
|
227 |
|
228 |
-
|
229 |
# with col1:
|
230 |
# st.markdown("### Uploaded Resume:")
|
231 |
# # if resume_path.endswith('.docx'):
|
@@ -243,8 +272,11 @@ if uploaded_resume and uploaded_job_description:
|
|
243 |
# display_score(similarity_score, pie_colors)
|
244 |
|
245 |
if generated_resume is not None:
|
|
|
246 |
from io import BytesIO
|
247 |
|
|
|
|
|
248 |
|
249 |
doc = Document()
|
250 |
doc.add_paragraph(generated_resume)
|
@@ -253,14 +285,14 @@ if uploaded_resume and uploaded_job_description:
|
|
253 |
doc.save(resume_bytes)
|
254 |
resume_bytes.seek(0)
|
255 |
|
256 |
-
|
257 |
with col1:
|
258 |
-
save_docx_as_pdf(
|
|
|
|
|
|
|
|
|
259 |
display_doc_as_image('tailored_resume.pdf')
|
260 |
-
# with col2:
|
261 |
-
# st.markdown("### Tailored Resume:")
|
262 |
-
# save_docx_as_pdf(generated_resume, 'tailored_resume.pdf')
|
263 |
-
# display_doc_as_image(generated_resume)
|
264 |
|
265 |
|
266 |
st.download_button(
|
|
|
153 |
ax.axis('equal')
|
154 |
st.pyplot(fig)
|
155 |
|
156 |
+
|
157 |
+
def save_file(file_name):
|
158 |
+
if hasattr(uploaded_file, 'name'):
|
159 |
+
file_path = os.path.join("/tmp", uploaded_file.name)
|
160 |
+
with open(file_path, "wb") as f:
|
161 |
+
f.write(uploaded_file.read())
|
162 |
+
else:
|
163 |
+
file_path = os.path.join("/tmp", "temp_upload")
|
164 |
+
with open(file_path, "w") as f:
|
165 |
+
f.write(uploaded_file)
|
166 |
+
return file_path
|
167 |
+
|
168 |
+
|
169 |
def save_docx_as_pdf(doc_content, output_path='output.pdf'):
|
170 |
# Save document content as a .docx file
|
171 |
temp_doc_path = 'temp.docx'
|
|
|
180 |
|
181 |
# subprocess.run(['libreoffice', '--headless', '--convert-to', 'pdf', temp_doc_path, '--outdir', os.path.dirname(output_path)])
|
182 |
|
183 |
+
def save_docx_as_pdf(input_path, output_path='output.pdf'):
|
184 |
+
if input_path.lower().endswith('.docx'):
|
185 |
+
from docx2pdf import convert
|
186 |
+
convert(input_path, output_path)
|
187 |
+
elif input_path.lower().endswith('.pdf'):
|
188 |
+
shutil.copy(input_path, output_path)
|
189 |
+
else:
|
190 |
+
raise ValueError("Unsupported file format. Please upload a .docx or .pdf file.")
|
191 |
+
|
192 |
# if uploaded_resume.type == "application/vnd.openxmlformats-officedocument.wordprocessingml.document":
|
193 |
# save_docx_as_pdf(resume_path, 'uploaded_resume.pdf')
|
194 |
# display_doc_as_image('uploaded_resume.pdf')
|
195 |
|
196 |
def display_doc_as_image(pdf_path):
|
197 |
+
try:
|
198 |
+
images = convert_from_path(pdf_path, size=800)
|
199 |
+
display(Image(filename=images[0].filename))
|
200 |
+
except Exception as e:
|
201 |
+
st.error(f"Failed to display image: {str(e)}")
|
202 |
+
|
203 |
+
def display_doc_as_image1(pdf_path):
|
204 |
# poppler_path = 'usr/bin'
|
205 |
# images = convert_from_path(pdf_path, poppler_path=poppler_path)
|
206 |
# for img in images:
|
|
|
254 |
</script>
|
255 |
""", unsafe_allow_html=True)
|
256 |
|
257 |
+
|
258 |
# with col1:
|
259 |
# st.markdown("### Uploaded Resume:")
|
260 |
# # if resume_path.endswith('.docx'):
|
|
|
272 |
# display_score(similarity_score, pie_colors)
|
273 |
|
274 |
if generated_resume is not None:
|
275 |
+
|
276 |
from io import BytesIO
|
277 |
|
278 |
+
gen_resume_path = save_uploaded_file(generated_resume)
|
279 |
+
# uploaded_resume_path = save_uploaded_file(resume)
|
280 |
|
281 |
doc = Document()
|
282 |
doc.add_paragraph(generated_resume)
|
|
|
285 |
doc.save(resume_bytes)
|
286 |
resume_bytes.seek(0)
|
287 |
|
288 |
+
col1, col2 = st.columns(2)
|
289 |
with col1:
|
290 |
+
save_docx_as_pdf(resume_path, 'uploaded_resume.pdf')
|
291 |
+
display_doc_as_image('uploaded_resume.pdf')
|
292 |
+
with col2:
|
293 |
+
st.markdown("### Tailored Resume:")
|
294 |
+
save_docx_as_pdf(gen_resume_path, 'tailored_resume.pdf')
|
295 |
display_doc_as_image('tailored_resume.pdf')
|
|
|
|
|
|
|
|
|
296 |
|
297 |
|
298 |
st.download_button(
|