Spaces:
Running
Running
from fpdf import FPDF | |
from datetime import datetime | |
def generate_report(job_role, cv_summary, answers, evaluation): | |
pdf = FPDF() | |
pdf.add_page() | |
# Header | |
pdf.set_font("Arial", 'B', 16) | |
pdf.cell(0, 10, f"Interview Report - {job_role}", 0, 1, 'C') | |
pdf.ln(10) | |
# Candidate Summary | |
pdf.set_font("Arial", 'B', 12) | |
pdf.cell(0, 10, "Candidate Summary:", 0, 1) | |
pdf.set_font("Arial", '', 10) | |
pdf.multi_cell(0, 7, f"Experience: {cv_summary['experience']} years\nSkills Match: {cv_summary['skills_match']:.1%}") | |
# Results | |
pdf.ln(5) | |
pdf.set_font("Arial", 'B', 12) | |
pdf.cell(0, 10, f"Overall Score: {evaluation['score']}/10 ({evaluation['band']})", 0, 1) | |
# Questions | |
pdf.set_font("Arial", 'B', 12) | |
pdf.cell(0, 10, "Question Details:", 0, 1) | |
pdf.set_font("Arial", '', 10) | |
for i, ans in enumerate(answers): | |
pdf.cell(0, 7, f"Q{i+1}: {ans['question']['text']}", 0, 1) | |
pdf.multi_cell(0, 7, f"Answer: {ans['answer']}") | |
pdf.multi_cell(0, 7, f"Feedback: {ans['evaluation']['feedback']} (Score: {ans['evaluation']['score']}/10)") | |
pdf.ln(3) | |
# Save | |
os.makedirs("data/interviews", exist_ok=True) | |
path = f"data/interviews/report_{datetime.now().strftime('%Y%m%d_%H%M%S')}.pdf" | |
pdf.output(path) | |
return path |