pktpaulie commited on
Commit
0fba36c
·
verified ·
1 Parent(s): 2ad2801

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +146 -158
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
- 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.")
 
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.")