Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -266,16 +266,34 @@ def display_pdf_page(pdf_path):
|
|
266 |
except Exception as e:
|
267 |
st.error(f"Failed to display image: {str(e)}")
|
268 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
269 |
def display_pdf_pages_as_images(pdf_path):
|
270 |
try:
|
271 |
with pdfplumber.open(pdf_path) as pdf:
|
|
|
|
|
|
|
|
|
272 |
for i, page in enumerate(pdf.pages):
|
273 |
-
st.markdown(f"#### Page {i + 1}")
|
274 |
# Convert the page to an image
|
275 |
image = page.to_image()
|
276 |
-
#
|
277 |
-
|
278 |
-
|
|
|
|
|
279 |
except Exception as e:
|
280 |
st.error(f"Failed to display PDF as image: {str(e)}")
|
281 |
|
@@ -339,9 +357,9 @@ if uploaded_resume and uploaded_job_description:
|
|
339 |
|
340 |
if generated_resume is not None:
|
341 |
st.markdown("---")
|
342 |
-
st.title("
|
343 |
doc = Document()
|
344 |
-
doc.add_paragraph(generated_resume)
|
345 |
|
346 |
# Save the generated document as a .docx file in memory
|
347 |
resume_bytes = BytesIO()
|
@@ -354,36 +372,59 @@ if uploaded_resume and uploaded_job_description:
|
|
354 |
# Convert the generated .docx to a .pdf
|
355 |
gen_pdf_path = save_uploaded_file(gen_docx_path)
|
356 |
# st.write(display_docx_content(gen_pdf_path))
|
357 |
-
|
358 |
-
|
|
|
|
|
|
|
|
|
|
|
359 |
col1, col2 = st.columns(2)
|
360 |
with col1:
|
361 |
-
st.
|
362 |
-
|
363 |
-
|
|
|
|
|
|
|
364 |
with col2:
|
365 |
-
st.
|
366 |
-
|
367 |
-
|
368 |
-
|
369 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
370 |
|
371 |
-
|
372 |
-
|
373 |
-
|
374 |
-
|
375 |
-
|
376 |
-
|
377 |
-
|
378 |
-
|
379 |
-
|
380 |
-
|
381 |
-
|
382 |
-
|
383 |
-
|
384 |
-
|
385 |
-
|
386 |
-
|
387 |
|
388 |
|
389 |
else:
|
|
|
266 |
except Exception as e:
|
267 |
st.error(f"Failed to display image: {str(e)}")
|
268 |
|
269 |
+
# def display_pdf_pages_as_images(pdf_path):
|
270 |
+
# try:
|
271 |
+
# with pdfplumber.open(pdf_path) as pdf:
|
272 |
+
# for i, page in enumerate(pdf.pages):
|
273 |
+
# st.markdown(f"#### Page {i + 1}")
|
274 |
+
# # Convert the page to an image
|
275 |
+
# image = page.to_image()
|
276 |
+
# # Render the image using Streamlit
|
277 |
+
# # st.image(image.original, use_column_width=True)
|
278 |
+
# st.image(image.original, use_container_width=False)
|
279 |
+
# except Exception as e:
|
280 |
+
# st.error(f"Failed to display PDF as image: {str(e)}")
|
281 |
+
|
282 |
def display_pdf_pages_as_images(pdf_path):
|
283 |
try:
|
284 |
with pdfplumber.open(pdf_path) as pdf:
|
285 |
+
num_pages = len(pdf.pages)
|
286 |
+
# Create a container with columns for each page
|
287 |
+
columns = st.columns(num_pages)
|
288 |
+
|
289 |
for i, page in enumerate(pdf.pages):
|
|
|
290 |
# Convert the page to an image
|
291 |
image = page.to_image()
|
292 |
+
# Display each page image in its respective column
|
293 |
+
with columns[i]:
|
294 |
+
st.markdown(f"#### Page {i + 1}")
|
295 |
+
st.image(image.original, use_container_width=True)
|
296 |
+
|
297 |
except Exception as e:
|
298 |
st.error(f"Failed to display PDF as image: {str(e)}")
|
299 |
|
|
|
357 |
|
358 |
if generated_resume is not None:
|
359 |
st.markdown("---")
|
360 |
+
st.title("Uploaded Resumes")
|
361 |
doc = Document()
|
362 |
+
doc.add_paragraph(generated_resume)
|
363 |
|
364 |
# Save the generated document as a .docx file in memory
|
365 |
resume_bytes = BytesIO()
|
|
|
372 |
# Convert the generated .docx to a .pdf
|
373 |
gen_pdf_path = save_uploaded_file(gen_docx_path)
|
374 |
# st.write(display_docx_content(gen_pdf_path))
|
375 |
+
|
376 |
+
)
|
377 |
+
st.markdown("### Uploaded Resume")
|
378 |
+
save_docx_as_pdf(resume_path, '/tmp/uploaded_resume.pdf')
|
379 |
+
display_pdf_pages_as_images(resume_path)
|
380 |
+
|
381 |
+
st.success(f"Download tailored resume")
|
382 |
col1, col2 = st.columns(2)
|
383 |
with col1:
|
384 |
+
st.download_button(
|
385 |
+
label="Generated Resume (PDF)",
|
386 |
+
data=open(gen_pdf_path, 'rb').read(),
|
387 |
+
file_name="tailored_resume.pdf",
|
388 |
+
mime="application/pdf"
|
389 |
+
)
|
390 |
with col2:
|
391 |
+
st.download_button(
|
392 |
+
label="Generated Resume (Word)",
|
393 |
+
data=resume_bytes,
|
394 |
+
file_name="tailored_resume.docx",
|
395 |
+
mime="application/vnd.openxmlformats-officedocument.wordprocessingml.document"
|
396 |
+
)
|
397 |
+
|
398 |
+
|
399 |
+
# Display uploaded and generated resumes side-by-side
|
400 |
+
# col1, col2 = st.columns(2)
|
401 |
+
# with col1:
|
402 |
+
# st.markdown("### Uploaded Resume")
|
403 |
+
# save_docx_as_pdf(resume_path, '/tmp/uploaded_resume.pdf')
|
404 |
+
# display_pdf_pages_as_images(resume_path)
|
405 |
+
# with col2:
|
406 |
+
# st.markdown("### Tailored Resume")
|
407 |
+
# # display_pdf_pages_as_images(gen_pdf_path)
|
408 |
+
# display_content_with_page_numbers(generated_resume, 290)
|
409 |
+
# st.write(generated_resume)
|
410 |
+
# # display_content_with_page_numbers(generated_resume, 290)
|
411 |
|
412 |
+
# st.success(f"Download tailored resume")
|
413 |
+
# col1, col2 = st.columns(2)
|
414 |
+
# with col1:
|
415 |
+
# st.download_button(
|
416 |
+
# label="Generated Resume (PDF)",
|
417 |
+
# data=open(gen_pdf_path, 'rb').read(),
|
418 |
+
# file_name="tailored_resume.pdf",
|
419 |
+
# mime="application/pdf"
|
420 |
+
# )
|
421 |
+
# with col2:
|
422 |
+
# st.download_button(
|
423 |
+
# label="Generated Resume (Word)",
|
424 |
+
# data=resume_bytes,
|
425 |
+
# file_name="tailored_resume.docx",
|
426 |
+
# mime="application/vnd.openxmlformats-officedocument.wordprocessingml.document"
|
427 |
+
# )
|
428 |
|
429 |
|
430 |
else:
|