Musabbirkm commited on
Commit
7666736
·
verified ·
1 Parent(s): 68da6cb

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +108 -92
app.py CHANGED
@@ -82,14 +82,30 @@ st.markdown("""
82
  margin: 0 auto;
83
  width: 150px;
84
  }
 
85
  .card {
86
  background-color: #2d3748;
87
  padding: 15px;
88
  border-radius: 10px;
89
  box-shadow: 0 4px 8px rgba(0,0,0,0.1);
90
  margin-bottom: 20px;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
91
  }
92
-
93
 
94
  [data-testid="stSidebar"],
95
  .st-emotion-cache-6qob1r {
@@ -570,103 +586,103 @@ if page == "CV Maker": # Assuming 'page' is defined elsewhere; use 'if' instead
570
  print(f"Error details: {str(e)}")
571
  return f"Error generating CV: {str(e)}"
572
 
573
- def generate_cv_pdf(cv_content: str) -> BytesIO:
574
- try:
575
- # Initialize BytesIO buffer
576
- buffer = BytesIO()
577
 
578
- # Create a SimpleDocTemplate for the PDF
579
- doc = SimpleDocTemplate(buffer, pagesize=letter)
580
 
581
- # Define styles
582
- styles = getSampleStyleSheet()
583
- heading_style = ParagraphStyle(
584
- name='Heading',
585
- fontSize=14,
586
- leading=16,
587
- spaceAfter=12,
588
- fontName='Helvetica-Bold'
589
- )
590
- body_style = ParagraphStyle(
591
- name='Body',
592
- fontSize=11,
593
- leading=14,
594
- spaceAfter=8,
595
- fontName='Helvetica'
596
- )
597
- bullet_style = ParagraphStyle(
598
- name='Bullet',
599
- fontSize=11,
600
- leading=14,
601
- leftIndent=20,
602
- bulletIndent=10,
603
- spaceAfter=8,
604
- fontName='Helvetica'
605
- )
606
 
607
- # Initialize flowables list
608
- flowables = []
609
 
610
- # Validate cv_content
611
- if not cv_content or not isinstance(cv_content, str):
612
- logger.error("Invalid or empty cv_content provided")
613
- raise ValueError("CV content is empty or invalid")
614
 
615
- # Split content into sections
616
- sections = cv_content.split('===')
617
- logger.debug(f"Number of sections: {len(sections)}")
618
- logger.debug(f"Sections: {sections}")
619
 
620
- # Process sections
621
- for i in range(0, len(sections), 2):
622
- if i + 1 >= len(sections):
623
- logger.warning("Incomplete section pair detected, stopping processing")
624
- break
625
 
626
- title = sections[i].strip()
627
- content = sections[i + 1].strip().split('\n')
628
- logger.debug(f"Processing section: {title}")
629
 
630
- # Add section title
631
- flowables.append(Paragraph(title, heading_style))
632
- flowables.append(Spacer(1, 6))
633
 
634
- # Process section content
635
- if title in ["Skills", "Certifications"]:
636
- # Handle bullet points for Skills and Certifications
637
- bullet_items = []
638
- for line in content:
639
- if line.strip():
640
- # Sanitize text to avoid encoding issues
641
- sanitized_line = line.strip().encode('ascii', 'ignore').decode('ascii')
642
- bullet_items.append(ListItem(Paragraph(sanitized_line, bullet_style)))
643
- if bullet_items:
644
- flowables.append(ListFlowable(bullet_items, bulletType='bullet', start='circle'))
645
- else:
646
- logger.warning(f"No valid bullet items for section: {title}")
647
- else:
648
- # Handle regular paragraphs
649
- for line in content:
650
- if line.strip():
651
- # Sanitize text to avoid encoding issues
652
- sanitized_line = line.strip().encode('ascii', 'ignore').decode('ascii')
653
- flowables.append(Paragraph(sanitized_line, body_style))
654
 
655
- flowables.append(Spacer(1, 12))
656
 
657
- # Build the PDF
658
- logger.debug("Building PDF with flowables")
659
- doc.build(flowables)
660
 
661
- # Ensure buffer is ready to be read
662
- buffer.seek(0)
663
- logger.debug("PDF generation completed successfully")
664
 
665
- return buffer
666
 
667
- except Exception as e:
668
- logger.error(f"Error generating PDF: {str(e)}")
669
- raise Exception(f"Failed to generate PDF: {str(e)}")
670
 
671
  with st.form("cv_form"):
672
  col1, col2 = st.columns(2)
@@ -698,13 +714,13 @@ if page == "CV Maker": # Assuming 'page' is defined elsewhere; use 'if' instead
698
  file_name="John_Doe_CV.txt",
699
  mime="text/plain"
700
  )
701
- pdf_buffer = generate_cv_pdf(cv_content)
702
- st.download_button(
703
- label="Download CV (PDF)",
704
- data=pdf_buffer,
705
- file_name="John_Doe_CV.pdf",
706
- mime="application/pdf"
707
- )
708
  else:
709
  st.error(cv_content)
710
 
@@ -819,7 +835,7 @@ elif page == "Career Insights":
819
  days_back=7
820
  current_date = datetime.now().strftime('%Y-%m-%d')
821
  start_date = (datetime.now() - timedelta(days=days_back)).strftime('%Y-%m-%d')
822
- if not isinstance(yesterday, str):
823
  raise ValueError("Invalid date format for from_param")
824
  job_news = newsapi.get_everything(
825
  q='(jobs OR hiring OR recruitment OR employment OR "job market") AND (India OR Indian)',
 
82
  margin: 0 auto;
83
  width: 150px;
84
  }
85
+
86
  .card {
87
  background-color: #2d3748;
88
  padding: 15px;
89
  border-radius: 10px;
90
  box-shadow: 0 4px 8px rgba(0,0,0,0.1);
91
  margin-bottom: 20px;
92
+ color: #ffffff !important;
93
+ }
94
+ .card h4 {
95
+ color: #ffffff !important;
96
+ margin-bottom: 10px;
97
+ }
98
+ .card p {
99
+ color: #e2e8f0 !important;
100
+ margin: 5px 0;
101
+ }
102
+ .card a {
103
+ color: #63b3ed !important;
104
+ text-decoration: none;
105
+ }
106
+ .card a:hover {
107
+ color: #90cdf4 !important;
108
  }
 
109
 
110
  [data-testid="stSidebar"],
111
  .st-emotion-cache-6qob1r {
 
586
  print(f"Error details: {str(e)}")
587
  return f"Error generating CV: {str(e)}"
588
 
589
+ # def generate_cv_pdf(cv_content: str) -> BytesIO:
590
+ # try:
591
+ # # Initialize BytesIO buffer
592
+ # buffer = BytesIO()
593
 
594
+ # # Create a SimpleDocTemplate for the PDF
595
+ # doc = SimpleDocTemplate(buffer, pagesize=letter)
596
 
597
+ # # Define styles
598
+ # styles = getSampleStyleSheet()
599
+ # heading_style = ParagraphStyle(
600
+ # name='Heading',
601
+ # fontSize=14,
602
+ # leading=16,
603
+ # spaceAfter=12,
604
+ # fontName='Helvetica-Bold'
605
+ # )
606
+ # body_style = ParagraphStyle(
607
+ # name='Body',
608
+ # fontSize=11,
609
+ # leading=14,
610
+ # spaceAfter=8,
611
+ # fontName='Helvetica'
612
+ # )
613
+ # bullet_style = ParagraphStyle(
614
+ # name='Bullet',
615
+ # fontSize=11,
616
+ # leading=14,
617
+ # leftIndent=20,
618
+ # bulletIndent=10,
619
+ # spaceAfter=8,
620
+ # fontName='Helvetica'
621
+ # )
622
 
623
+ # # Initialize flowables list
624
+ # flowables = []
625
 
626
+ # # Validate cv_content
627
+ # if not cv_content or not isinstance(cv_content, str):
628
+ # logger.error("Invalid or empty cv_content provided")
629
+ # raise ValueError("CV content is empty or invalid")
630
 
631
+ # # Split content into sections
632
+ # sections = cv_content.split('===')
633
+ # logger.debug(f"Number of sections: {len(sections)}")
634
+ # logger.debug(f"Sections: {sections}")
635
 
636
+ # # Process sections
637
+ # for i in range(0, len(sections), 2):
638
+ # if i + 1 >= len(sections):
639
+ # logger.warning("Incomplete section pair detected, stopping processing")
640
+ # break
641
 
642
+ # title = sections[i].strip()
643
+ # content = sections[i + 1].strip().split('\n')
644
+ # logger.debug(f"Processing section: {title}")
645
 
646
+ # # Add section title
647
+ # flowables.append(Paragraph(title, heading_style))
648
+ # flowables.append(Spacer(1, 6))
649
 
650
+ # # Process section content
651
+ # if title in ["Skills", "Certifications"]:
652
+ # # Handle bullet points for Skills and Certifications
653
+ # bullet_items = []
654
+ # for line in content:
655
+ # if line.strip():
656
+ # # Sanitize text to avoid encoding issues
657
+ # sanitized_line = line.strip().encode('ascii', 'ignore').decode('ascii')
658
+ # bullet_items.append(ListItem(Paragraph(sanitized_line, bullet_style)))
659
+ # if bullet_items:
660
+ # flowables.append(ListFlowable(bullet_items, bulletType='bullet', start='circle'))
661
+ # else:
662
+ # logger.warning(f"No valid bullet items for section: {title}")
663
+ # else:
664
+ # # Handle regular paragraphs
665
+ # for line in content:
666
+ # if line.strip():
667
+ # # Sanitize text to avoid encoding issues
668
+ # sanitized_line = line.strip().encode('ascii', 'ignore').decode('ascii')
669
+ # flowables.append(Paragraph(sanitized_line, body_style))
670
 
671
+ # flowables.append(Spacer(1, 12))
672
 
673
+ # # Build the PDF
674
+ # logger.debug("Building PDF with flowables")
675
+ # doc.build(flowables)
676
 
677
+ # # Ensure buffer is ready to be read
678
+ # buffer.seek(0)
679
+ # logger.debug("PDF generation completed successfully")
680
 
681
+ # return buffer
682
 
683
+ # except Exception as e:
684
+ # logger.error(f"Error generating PDF: {str(e)}")
685
+ # raise Exception(f"Failed to generate PDF: {str(e)}")
686
 
687
  with st.form("cv_form"):
688
  col1, col2 = st.columns(2)
 
714
  file_name="John_Doe_CV.txt",
715
  mime="text/plain"
716
  )
717
+ # pdf_buffer = generate_cv_pdf(cv_content)
718
+ # st.download_button(
719
+ # label="Download CV (PDF)",
720
+ # data=pdf_buffer,
721
+ # file_name="John_Doe_CV.pdf",
722
+ # mime="application/pdf"
723
+ # )
724
  else:
725
  st.error(cv_content)
726
 
 
835
  days_back=7
836
  current_date = datetime.now().strftime('%Y-%m-%d')
837
  start_date = (datetime.now() - timedelta(days=days_back)).strftime('%Y-%m-%d')
838
+ if not isinstance(days_back, str):
839
  raise ValueError("Invalid date format for from_param")
840
  job_news = newsapi.get_everything(
841
  q='(jobs OR hiring OR recruitment OR employment OR "job market") AND (India OR Indian)',