pktpaulie commited on
Commit
d66e1fd
·
verified ·
1 Parent(s): 7cf954e

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +143 -143
app.py CHANGED
@@ -601,158 +601,158 @@ if uploaded_resume and uploaded_job_description:
601
  # similarity_score, pie_colors = get_score(resume_path, job_description_path)
602
  # display_score(similarity_score, pie_colors)
603
 
604
- if generated_resume is not None:
605
- doc = Document()
606
- doc.add_paragraph(generated_resume) # Add the generated content to the document
607
-
608
- # Save the generated document as a .docx file in memory
609
- resume_bytes = BytesIO()
610
- doc.save(resume_bytes)
611
- resume_bytes.seek(0)
612
-
613
- # Save the .docx to a temporary file
614
- gen_docx_path = save_bytes_to_tempfile(resume_bytes.getvalue(), 'docx')
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
- # Display uploaded and generated resumes side-by-side
627
- if st.button("View Uploaded Resume"):
628
- col1, col2 = st.columns(2)
629
- with col1:
630
- st.markdown("### Uploaded Resume:")
631
- save_docx_as_pdf(resume_path, '/tmp/uploaded_resume.pdf')
632
- # display_doc_as_image1('/tmp/uploaded_resume.pdf')
633
- display_pdf_pages_as_images(resume_path)
634
- with col2:
635
- st.markdown("### Tailored Resume:")
636
- # display_doc_as_image2(gen_pdf_path)
637
- # display_pdf_pages_as_images(gen_pdf_path)
638
- # st.write(generated_resume)
639
- display_content_with_page_numbers(generated_resume, 290)
640
- st.success(f"Download tailored resume")
641
- st.download_button(
642
- label="Generated Resume (PDF)",
643
- data=open(gen_pdf_path, 'rb').read(),
644
- file_name="generated_resume.pdf",
645
- mime="application/pdf"
646
- )
647
- st.download_button(
648
- label="Generated Resume (Word)",
649
- data=resume_bytes,
650
- file_name="tailored_resume.docx",
651
- mime="application/vnd.openxmlformats-officedocument.wordprocessingml.document"
652
- )
653
- else:
654
- st.success(f"Download tailored resume")
655
- st.download_button(
656
- label="Generated Resume (PDF)",
657
- data=open(gen_pdf_path, 'rb').read(),
658
- file_name="generated_resume.pdf",
659
- mime="application/pdf"
660
- )
661
- st.download_button(
662
- label="Generated Resume (Word)",
663
- data=resume_bytes,
664
- file_name="tailored_resume.docx",
665
- mime="application/vnd.openxmlformats-officedocument.wordprocessingml.document"
666
  )
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
667
 
668
- # from io import BytesIO
669
- # doc = Document()
670
-
671
- # with tempfile.NamedTemporaryFile(delete=False, suffix=".docx") as temp_doc:
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
- # # Convert DOCX to PDF
697
- # # pdf_path = f"temp_{os.path.basename(temp_doc.name)}.pdf"
698
- # # convert(temp_doc.name, pdf_path)
699
- # # save_docx_as_pdf(temp_doc.name, pdf_path)
700
- # pdf_path = '/tmp/generated_resume.docx'
701
- # doc.save(pdf_path)
702
-
703
- # # pdf_path = save_uploaded_file(resume_bytes)
704
- # save_docx_as_pdf(generated_resume, pdf_path)
705
-
706
- # # Display resumes side by side
707
- # col1, col2 = st.columns(2)
708
- # with col1:
709
- # st.write("Uploaded Resume:")
710
- # if resume_path:
711
- # display_doc_as_image(resume_path)
712
- # else:
713
- # st.warning("No resume file found")
714
-
715
- # with col2:
716
- # st.write("Generated Resume:")
717
- # if pdf_path:
718
- # display_doc_as_image(pdf_path)
719
- # else:
720
- # st.warning("No generated resume file found")
721
 
722
- # Allow users to download both PDFs
723
- # st.download_button(
724
- # label="Download Uploaded Resume",
725
- # data=resume_bytes,
726
- # file_name="uploaded_resume.pdf",
727
- # mime="application/pdf"
728
- # )
729
 
730
- # doc = Document()
731
- # doc.add_paragraph(generated_resume)
 
 
 
 
 
732
 
733
- # resume_bytes = BytesIO()
734
- # doc.save(resume_bytes)
735
- # resume_bytes.seek(0)
736
-
737
- # gen_resume_path = save_uploaded_file(resume_bytes)
738
- # # uploaded_resume_path = save_uploaded_file(resume)
739
-
740
- # col1, col2 = st.columns(2)
741
- # with col1:
742
- # save_docx_as_pdf(resume_path, 'uploaded_resume.pdf')
743
- # display_doc_as_image('uploaded_resume.pdf')
744
- # with col2:
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.")
 
601
  # similarity_score, pie_colors = get_score(resume_path, job_description_path)
602
  # display_score(similarity_score, pie_colors)
603
 
604
+ if generated_resume is not None:
605
+ doc = Document()
606
+ doc.add_paragraph(generated_resume) # Add the generated content to the document
607
+
608
+ # Save the generated document as a .docx file in memory
609
+ resume_bytes = BytesIO()
610
+ doc.save(resume_bytes)
611
+ resume_bytes.seek(0)
612
+
613
+ # Save the .docx to a temporary file
614
+ gen_docx_path = save_bytes_to_tempfile(resume_bytes.getvalue(), 'docx')
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
+ # Display uploaded and generated resumes side-by-side
627
+ if st.button("View Uploaded Resume"):
628
+ col1, col2 = st.columns(2)
629
+ with col1:
630
+ st.markdown("### Uploaded Resume:")
631
+ save_docx_as_pdf(resume_path, '/tmp/uploaded_resume.pdf')
632
+ # display_doc_as_image1('/tmp/uploaded_resume.pdf')
633
+ display_pdf_pages_as_images(resume_path)
634
+ with col2:
635
+ st.markdown("### Tailored Resume:")
636
+ # display_doc_as_image2(gen_pdf_path)
637
+ # display_pdf_pages_as_images(gen_pdf_path)
638
+ # st.write(generated_resume)
639
+ display_content_with_page_numbers(generated_resume, 290)
640
+ st.success(f"Download tailored resume")
641
+ st.download_button(
642
+ label="Generated Resume (PDF)",
643
+ data=open(gen_pdf_path, 'rb').read(),
644
+ file_name="generated_resume.pdf",
645
+ mime="application/pdf"
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
646
  )
647
+ st.download_button(
648
+ label="Generated Resume (Word)",
649
+ data=resume_bytes,
650
+ file_name="tailored_resume.docx",
651
+ mime="application/vnd.openxmlformats-officedocument.wordprocessingml.document"
652
+ )
653
+ else:
654
+ st.success(f"Download tailored resume")
655
+ st.download_button(
656
+ label="Generated Resume (PDF)",
657
+ data=open(gen_pdf_path, 'rb').read(),
658
+ file_name="generated_resume.pdf",
659
+ mime="application/pdf"
660
+ )
661
+ st.download_button(
662
+ label="Generated Resume (Word)",
663
+ data=resume_bytes,
664
+ file_name="tailored_resume.docx",
665
+ mime="application/vnd.openxmlformats-officedocument.wordprocessingml.document"
666
+ )
667
 
668
+ # from io import BytesIO
669
+ # doc = Document()
670
+
671
+ # with tempfile.NamedTemporaryFile(delete=False, suffix=".docx") as temp_doc:
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
+ # # Convert DOCX to PDF
697
+ # # pdf_path = f"temp_{os.path.basename(temp_doc.name)}.pdf"
698
+ # # convert(temp_doc.name, pdf_path)
699
+ # # save_docx_as_pdf(temp_doc.name, pdf_path)
700
+ # pdf_path = '/tmp/generated_resume.docx'
701
+ # doc.save(pdf_path)
702
 
703
+ # # pdf_path = save_uploaded_file(resume_bytes)
704
+ # save_docx_as_pdf(generated_resume, pdf_path)
 
 
 
 
 
 
 
 
705
 
706
+ # # Display resumes side by side
707
+ # col1, col2 = st.columns(2)
708
+ # with col1:
709
+ # st.write("Uploaded Resume:")
710
+ # if resume_path:
711
+ # display_doc_as_image(resume_path)
712
+ # else:
713
+ # st.warning("No resume file found")
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
714
 
715
+ # with col2:
716
+ # st.write("Generated Resume:")
717
+ # if pdf_path:
718
+ # display_doc_as_image(pdf_path)
719
+ # else:
720
+ # st.warning("No generated resume file found")
 
721
 
722
+ # Allow users to download both PDFs
723
+ # st.download_button(
724
+ # label="Download Uploaded Resume",
725
+ # data=resume_bytes,
726
+ # file_name="uploaded_resume.pdf",
727
+ # mime="application/pdf"
728
+ # )
729
 
730
+ # doc = Document()
731
+ # doc.add_paragraph(generated_resume)
732
+
733
+ # resume_bytes = BytesIO()
734
+ # doc.save(resume_bytes)
735
+ # resume_bytes.seek(0)
736
+
737
+ # gen_resume_path = save_uploaded_file(resume_bytes)
738
+ # # uploaded_resume_path = save_uploaded_file(resume)
739
+
740
+ # col1, col2 = st.columns(2)
741
+ # with col1:
742
+ # save_docx_as_pdf(resume_path, 'uploaded_resume.pdf')
743
+ # display_doc_as_image('uploaded_resume.pdf')
744
+ # with col2:
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.")