pktpaulie commited on
Commit
2976fc9
·
verified ·
1 Parent(s): 8d9d609

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +74 -41
app.py CHANGED
@@ -188,7 +188,12 @@ def save_file(file_name):
188
 
189
  import tempfile
190
 
191
-
 
 
 
 
 
192
  def save_bytes_as_pdf(docx_bytes, output_path='output.pdf'):
193
  # Create a temporary directory
194
  with tempfile.TemporaryDirectory() as tmp_dir:
@@ -421,55 +426,83 @@ if uploaded_resume and uploaded_job_description:
421
  # display_score(similarity_score, pie_colors)
422
 
423
  if generated_resume is not None:
424
-
425
- from io import BytesIO
426
  doc = Document()
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
427
 
428
- with tempfile.NamedTemporaryFile(delete=False, suffix=".docx") as temp_doc:
429
- temp_doc_path = temp_doc.name
430
- doc.save(temp_doc_path)
431
 
432
- # Now pass the path to any function that expects a file path
433
- pdf_path = '/tmp/generated_resume.pdf'
434
- save_bytes_as_pdf(temp_doc_path, pdf_path)
435
 
436
- # Display the generated PDF or handle further processing
437
- display_doc_as_image(pdf_path)
438
 
439
- with tempfile.NamedTemporaryFile(suffix='.docx') as temp_doc:
440
- doc = Document()
441
- doc.add_paragraph(generated_resume)
442
- # doc.save(temp_doc.name)
443
-
444
- # resume_bytes = BytesIO()
445
- # doc.save(resume_bytes)
446
- # resume_bytes.seek(0)
447
 
448
- # Convert DOCX to PDF
449
- # pdf_path = f"temp_{os.path.basename(temp_doc.name)}.pdf"
450
- # convert(temp_doc.name, pdf_path)
451
- # save_docx_as_pdf(temp_doc.name, pdf_path)
452
- pdf_path = '/tmp/generated_resume.docx'
453
- doc.save(pdf_path)
454
 
455
- # pdf_path = save_uploaded_file(resume_bytes)
456
- save_docx_as_pdf(generated_resume, pdf_path)
457
 
458
- # Display resumes side by side
459
- col1, col2 = st.columns(2)
460
- with col1:
461
- st.write("Uploaded Resume:")
462
- if resume_path:
463
- display_doc_as_image(resume_path)
464
- else:
465
- st.warning("No resume file found")
466
 
467
- with col2:
468
- st.write("Generated Resume:")
469
- if pdf_path:
470
- display_doc_as_image(pdf_path)
471
- else:
472
- st.warning("No generated resume file found")
473
 
474
  # Allow users to download both PDFs
475
  # st.download_button(
 
188
 
189
  import tempfile
190
 
191
+ # Function to save a file from BytesIO to a temporary file
192
+ def save_bytes_to_tempfile(bytes_data, suffix):
193
+ with tempfile.NamedTemporaryFile(delete=False, suffix=suffix) as temp_file:
194
+ temp_file.write(bytes_data)
195
+ return temp_file.name
196
+
197
  def save_bytes_as_pdf(docx_bytes, output_path='output.pdf'):
198
  # Create a temporary directory
199
  with tempfile.TemporaryDirectory() as tmp_dir:
 
426
  # display_score(similarity_score, pie_colors)
427
 
428
  if generated_resume is not None:
 
 
429
  doc = Document()
430
+ doc.add_paragraph(generated_resume) # Add the generated content to the document
431
+
432
+ # Save the generated document as a .docx file in memory
433
+ resume_bytes = BytesIO()
434
+ doc.save(resume_bytes)
435
+ resume_bytes.seek(0)
436
+
437
+ # Save the .docx to a temporary file
438
+ gen_docx_path = save_bytes_to_tempfile(resume_bytes.getvalue(), '.docx')
439
+
440
+ # Convert the generated .docx to a .pdf
441
+ gen_pdf_path = '/tmp/tailored_resume.pdf'
442
+ save_docx_as_pdf(gen_docx_path, gen_pdf_path)
443
+
444
+ # Display uploaded and generated resumes side-by-side
445
+ col1, col2 = st.columns(2)
446
+ with col1:
447
+ st.markdown("### Uploaded Resume:")
448
+ save_docx_as_pdf(resume_path, '/tmp/uploaded_resume.pdf')
449
+ display_doc_as_image('/tmp/uploaded_resume.pdf')
450
+ with col2:
451
+ st.markdown("### Tailored Resume:")
452
+ display_doc_as_image(gen_pdf_path)
453
+ # from io import BytesIO
454
+ # doc = Document()
455
+
456
+ # with tempfile.NamedTemporaryFile(delete=False, suffix=".docx") as temp_doc:
457
+ # temp_doc_path = temp_doc.name
458
+ # doc.save(temp_doc_path)
459
+
460
 
461
+ # Convert the DOCX to PDF and display
462
+ # pdf_path = '/tmp/generated_resume.pdf'
463
+ # save_docx_as_pdf(temp_doc_path, pdf_path)
464
 
465
+ # # Now pass the path to any function that expects a file path
466
+ # pdf_path = '/tmp/generated_resume.pdf'
467
+ # save_bytes_as_pdf(temp_doc_path, pdf_path)
468
 
469
+ # # Display the generated PDF or handle further processing
470
+ # display_doc_as_image(pdf_path)
471
 
472
+ # with tempfile.NamedTemporaryFile(suffix='.docx') as temp_doc:
473
+ # doc = Document()
474
+ # doc.add_paragraph(generated_resume)
475
+ # # doc.save(temp_doc.name)
476
+
477
+ # # resume_bytes = BytesIO()
478
+ # # doc.save(resume_bytes)
479
+ # # resume_bytes.seek(0)
480
 
481
+ # # Convert DOCX to PDF
482
+ # # pdf_path = f"temp_{os.path.basename(temp_doc.name)}.pdf"
483
+ # # convert(temp_doc.name, pdf_path)
484
+ # # save_docx_as_pdf(temp_doc.name, pdf_path)
485
+ # pdf_path = '/tmp/generated_resume.docx'
486
+ # doc.save(pdf_path)
487
 
488
+ # # pdf_path = save_uploaded_file(resume_bytes)
489
+ # save_docx_as_pdf(generated_resume, pdf_path)
490
 
491
+ # # Display resumes side by side
492
+ # col1, col2 = st.columns(2)
493
+ # with col1:
494
+ # st.write("Uploaded Resume:")
495
+ # if resume_path:
496
+ # display_doc_as_image(resume_path)
497
+ # else:
498
+ # st.warning("No resume file found")
499
 
500
+ # with col2:
501
+ # st.write("Generated Resume:")
502
+ # if pdf_path:
503
+ # display_doc_as_image(pdf_path)
504
+ # else:
505
+ # st.warning("No generated resume file found")
506
 
507
  # Allow users to download both PDFs
508
  # st.download_button(