Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -585,174 +585,162 @@ if uploaded_resume and uploaded_job_description:
|
|
585 |
""", unsafe_allow_html=True)
|
586 |
|
587 |
|
588 |
-
# with col1:
|
589 |
-
# st.markdown("### Uploaded Resume:")
|
590 |
-
# # if resume_path.endswith('.docx'):
|
591 |
-
# # save_docx_as_pdf(uploaded_resume.getvalue().decode('utf-8'), 'uploaded_resume.pdf')
|
592 |
-
# # if uploaded_resume.type == "application/pdf":
|
593 |
-
# # display_doc_as_image(resume_path)
|
594 |
-
# # else:
|
595 |
-
# # save_docx_as_pdf(resume_path, 'uploaded_resume.pdf')
|
596 |
-
# display_doc_as_image(uploaded_resume)
|
597 |
-
|
598 |
-
|
599 |
-
|
600 |
# with st.spinner("Computing Match"):
|
601 |
# similarity_score, pie_colors = get_score(resume_path, job_description_path)
|
602 |
# display_score(similarity_score, pie_colors)
|
603 |
|
604 |
-
|
605 |
-
|
606 |
-
|
607 |
-
|
608 |
-
|
609 |
-
|
610 |
-
|
611 |
-
|
612 |
-
|
613 |
-
|
614 |
-
|
615 |
-
|
616 |
-
|
617 |
-
# Convert the generated .docx to a .pdf
|
618 |
-
# gen_pdf_path = '/tmp/tailored_resume.pdf'
|
619 |
-
gen_pdf_path = save_uploaded_file(gen_docx_path)
|
620 |
-
# st.write(display_docx_content(gen_pdf_path))
|
621 |
-
|
622 |
-
# save_docx_as_pdf0(gen_docx_path, gen_pdf_path)
|
623 |
-
# save_bytes_as_pdf(gen_docx_path, gen_pdf_path)
|
624 |
-
# save_docx_as_pdf2(gen_docx_path, gen_pdf_path)
|
625 |
|
626 |
-
|
627 |
-
|
628 |
-
|
629 |
-
|
630 |
-
st.
|
631 |
-
|
632 |
-
#
|
633 |
-
|
634 |
-
|
635 |
-
|
636 |
-
#
|
637 |
-
#
|
638 |
-
|
639 |
-
|
640 |
-
|
641 |
-
|
642 |
-
|
643 |
-
|
644 |
-
|
645 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
646 |
)
|
647 |
-
|
648 |
-
|
649 |
-
|
650 |
-
|
651 |
-
|
652 |
-
|
653 |
-
|
654 |
-
|
655 |
-
|
656 |
-
label="Generated Resume (
|
657 |
-
data=
|
658 |
-
file_name="
|
659 |
-
mime="application/
|
660 |
-
)
|
661 |
-
|
662 |
-
|
663 |
-
|
664 |
-
file_name="tailored_resume.docx",
|
665 |
-
mime="application/vnd.openxmlformats-officedocument.wordprocessingml.document"
|
666 |
-
)
|
667 |
|
668 |
-
|
669 |
-
|
670 |
-
|
671 |
-
|
672 |
-
# temp_doc_path = temp_doc.name
|
673 |
-
# doc.save(temp_doc_path)
|
674 |
-
|
675 |
-
|
676 |
-
# Convert the DOCX to PDF and display
|
677 |
-
# pdf_path = '/tmp/generated_resume.pdf'
|
678 |
-
# save_docx_as_pdf(temp_doc_path, pdf_path)
|
679 |
-
|
680 |
-
# # Now pass the path to any function that expects a file path
|
681 |
-
# pdf_path = '/tmp/generated_resume.pdf'
|
682 |
-
# save_bytes_as_pdf(temp_doc_path, pdf_path)
|
683 |
-
|
684 |
-
# # Display the generated PDF or handle further processing
|
685 |
-
# display_doc_as_image(pdf_path)
|
686 |
-
|
687 |
-
# with tempfile.NamedTemporaryFile(suffix='.docx') as temp_doc:
|
688 |
-
# doc = Document()
|
689 |
-
# doc.add_paragraph(generated_resume)
|
690 |
-
# # doc.save(temp_doc.name)
|
691 |
-
|
692 |
-
# # resume_bytes = BytesIO()
|
693 |
-
# # doc.save(resume_bytes)
|
694 |
-
# # resume_bytes.seek(0)
|
695 |
|
696 |
-
|
697 |
-
|
698 |
-
|
699 |
-
|
700 |
-
|
701 |
-
|
702 |
-
|
703 |
-
|
704 |
-
|
705 |
-
|
706 |
-
|
707 |
-
|
708 |
-
|
709 |
-
|
710 |
-
|
711 |
-
|
712 |
-
|
713 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
714 |
|
715 |
-
|
716 |
-
|
717 |
-
|
718 |
-
|
719 |
-
|
720 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
721 |
|
722 |
-
|
723 |
-
|
724 |
-
|
725 |
-
|
726 |
-
|
727 |
-
|
728 |
-
|
729 |
-
|
730 |
-
|
731 |
-
|
732 |
-
|
733 |
-
|
734 |
-
|
735 |
-
|
736 |
-
|
737 |
-
|
738 |
-
|
739 |
-
|
740 |
-
|
741 |
-
|
742 |
-
|
743 |
-
|
744 |
-
|
745 |
-
# st.markdown("### Tailored Resume:")
|
746 |
-
# save_docx_as_pdf(gen_resume_path, 'tailored_resume.pdf')
|
747 |
-
# display_doc_as_image('tailored_resume.pdf')
|
748 |
-
|
749 |
-
|
750 |
-
# st.download_button(
|
751 |
-
# label="Download Resume",
|
752 |
-
# data=resume_bytes,
|
753 |
-
# file_name="tailored_resume.docx",
|
754 |
-
# mime="application/vnd.openxmlformats-officedocument.wordprocessingml.document"
|
755 |
-
# )
|
756 |
|
757 |
else:
|
758 |
st.warning("Please upload both the resume and job description files.")
|
|
|
585 |
""", unsafe_allow_html=True)
|
586 |
|
587 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
588 |
# with st.spinner("Computing Match"):
|
589 |
# similarity_score, pie_colors = get_score(resume_path, job_description_path)
|
590 |
# display_score(similarity_score, pie_colors)
|
591 |
|
592 |
+
if generated_resume is not None:
|
593 |
+
doc = Document()
|
594 |
+
doc.add_paragraph(generated_resume) # Add the generated content to the document
|
595 |
+
|
596 |
+
# Save the generated document as a .docx file in memory
|
597 |
+
resume_bytes = BytesIO()
|
598 |
+
doc.save(resume_bytes)
|
599 |
+
resume_bytes.seek(0)
|
600 |
+
|
601 |
+
# Save the .docx to a temporary file
|
602 |
+
gen_docx_path = save_bytes_to_tempfile(resume_bytes.getvalue(), 'docx')
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
603 |
|
604 |
+
|
605 |
+
# Convert the generated .docx to a .pdf
|
606 |
+
# gen_pdf_path = '/tmp/tailored_resume.pdf'
|
607 |
+
gen_pdf_path = save_uploaded_file(gen_docx_path)
|
608 |
+
# st.write(display_docx_content(gen_pdf_path))
|
609 |
+
|
610 |
+
# save_docx_as_pdf0(gen_docx_path, gen_pdf_path)
|
611 |
+
# save_bytes_as_pdf(gen_docx_path, gen_pdf_path)
|
612 |
+
# save_docx_as_pdf2(gen_docx_path, gen_pdf_path)
|
613 |
+
|
614 |
+
# Display uploaded and generated resumes side-by-side
|
615 |
+
# if st.button("View Uploaded Resume"):
|
616 |
+
col1, col2 = st.columns(2)
|
617 |
+
with col1:
|
618 |
+
st.markdown("### Uploaded Resume:")
|
619 |
+
save_docx_as_pdf(resume_path, '/tmp/uploaded_resume.pdf')
|
620 |
+
# display_doc_as_image1('/tmp/uploaded_resume.pdf')
|
621 |
+
display_pdf_pages_as_images(resume_path)
|
622 |
+
with col2:
|
623 |
+
st.markdown("### Tailored Resume:")
|
624 |
+
# display_doc_as_image2(gen_pdf_path)
|
625 |
+
# display_pdf_pages_as_images(gen_pdf_path)
|
626 |
+
# st.write(generated_resume)
|
627 |
+
display_content_with_page_numbers(generated_resume, 290)
|
628 |
+
st.success(f"Download tailored resume")
|
629 |
+
st.download_button(
|
630 |
+
label="Generated Resume (PDF)",
|
631 |
+
data=open(gen_pdf_path, 'rb').read(),
|
632 |
+
file_name="generated_resume.pdf",
|
633 |
+
mime="application/pdf"
|
634 |
+
)
|
635 |
+
st.download_button(
|
636 |
+
label="Generated Resume (Word)",
|
637 |
+
data=resume_bytes,
|
638 |
+
file_name="tailored_resume.docx",
|
639 |
+
mime="application/vnd.openxmlformats-officedocument.wordprocessingml.document"
|
640 |
)
|
641 |
+
# else:
|
642 |
+
# st.success(f"Download tailored resume")
|
643 |
+
# st.download_button(
|
644 |
+
# label="Generated Resume (PDF)",
|
645 |
+
# data=open(gen_pdf_path, 'rb').read(),
|
646 |
+
# file_name="generated_resume.pdf",
|
647 |
+
# mime="application/pdf"
|
648 |
+
# )
|
649 |
+
# st.download_button(
|
650 |
+
# label="Generated Resume (Word)",
|
651 |
+
# data=resume_bytes,
|
652 |
+
# file_name="tailored_resume.docx",
|
653 |
+
# mime="application/vnd.openxmlformats-officedocument.wordprocessingml.document"
|
654 |
+
# )
|
655 |
+
|
656 |
+
# from io import BytesIO
|
657 |
+
# doc = Document()
|
|
|
|
|
|
|
658 |
|
659 |
+
# with tempfile.NamedTemporaryFile(delete=False, suffix=".docx") as temp_doc:
|
660 |
+
# temp_doc_path = temp_doc.name
|
661 |
+
# doc.save(temp_doc_path)
|
662 |
+
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
663 |
|
664 |
+
# Convert the DOCX to PDF and display
|
665 |
+
# pdf_path = '/tmp/generated_resume.pdf'
|
666 |
+
# save_docx_as_pdf(temp_doc_path, pdf_path)
|
667 |
+
|
668 |
+
# # Now pass the path to any function that expects a file path
|
669 |
+
# pdf_path = '/tmp/generated_resume.pdf'
|
670 |
+
# save_bytes_as_pdf(temp_doc_path, pdf_path)
|
671 |
+
|
672 |
+
# # Display the generated PDF or handle further processing
|
673 |
+
# display_doc_as_image(pdf_path)
|
674 |
+
|
675 |
+
# with tempfile.NamedTemporaryFile(suffix='.docx') as temp_doc:
|
676 |
+
# doc = Document()
|
677 |
+
# doc.add_paragraph(generated_resume)
|
678 |
+
# # doc.save(temp_doc.name)
|
679 |
+
|
680 |
+
# # resume_bytes = BytesIO()
|
681 |
+
# # doc.save(resume_bytes)
|
682 |
+
# # resume_bytes.seek(0)
|
683 |
+
|
684 |
+
# # Convert DOCX to PDF
|
685 |
+
# # pdf_path = f"temp_{os.path.basename(temp_doc.name)}.pdf"
|
686 |
+
# # convert(temp_doc.name, pdf_path)
|
687 |
+
# # save_docx_as_pdf(temp_doc.name, pdf_path)
|
688 |
+
# pdf_path = '/tmp/generated_resume.docx'
|
689 |
+
# doc.save(pdf_path)
|
690 |
+
|
691 |
+
# # pdf_path = save_uploaded_file(resume_bytes)
|
692 |
+
# save_docx_as_pdf(generated_resume, pdf_path)
|
693 |
|
694 |
+
# # Display resumes side by side
|
695 |
+
# col1, col2 = st.columns(2)
|
696 |
+
# with col1:
|
697 |
+
# st.write("Uploaded Resume:")
|
698 |
+
# if resume_path:
|
699 |
+
# display_doc_as_image(resume_path)
|
700 |
+
# else:
|
701 |
+
# st.warning("No resume file found")
|
702 |
+
|
703 |
+
# with col2:
|
704 |
+
# st.write("Generated Resume:")
|
705 |
+
# if pdf_path:
|
706 |
+
# display_doc_as_image(pdf_path)
|
707 |
+
# else:
|
708 |
+
# st.warning("No generated resume file found")
|
709 |
+
|
710 |
+
# Allow users to download both PDFs
|
711 |
+
# st.download_button(
|
712 |
+
# label="Download Uploaded Resume",
|
713 |
+
# data=resume_bytes,
|
714 |
+
# file_name="uploaded_resume.pdf",
|
715 |
+
# mime="application/pdf"
|
716 |
+
# )
|
717 |
+
|
718 |
+
# doc = Document()
|
719 |
+
# doc.add_paragraph(generated_resume)
|
720 |
|
721 |
+
# resume_bytes = BytesIO()
|
722 |
+
# doc.save(resume_bytes)
|
723 |
+
# resume_bytes.seek(0)
|
724 |
+
|
725 |
+
# gen_resume_path = save_uploaded_file(resume_bytes)
|
726 |
+
# # uploaded_resume_path = save_uploaded_file(resume)
|
727 |
+
|
728 |
+
# col1, col2 = st.columns(2)
|
729 |
+
# with col1:
|
730 |
+
# save_docx_as_pdf(resume_path, 'uploaded_resume.pdf')
|
731 |
+
# display_doc_as_image('uploaded_resume.pdf')
|
732 |
+
# with col2:
|
733 |
+
# st.markdown("### Tailored Resume:")
|
734 |
+
# save_docx_as_pdf(gen_resume_path, 'tailored_resume.pdf')
|
735 |
+
# display_doc_as_image('tailored_resume.pdf')
|
736 |
+
|
737 |
+
|
738 |
+
# st.download_button(
|
739 |
+
# label="Download Resume",
|
740 |
+
# data=resume_bytes,
|
741 |
+
# file_name="tailored_resume.docx",
|
742 |
+
# mime="application/vnd.openxmlformats-officedocument.wordprocessingml.document"
|
743 |
+
# )
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
744 |
|
745 |
else:
|
746 |
st.warning("Please upload both the resume and job description files.")
|