Spaces:
Sleeping
Sleeping
| # In cv_generator.py | |
| """Utility functions to generate CV content and produce PDF/DOCX files.""" | |
| from typing import Dict, List | |
| from docx import Document | |
| from reportlab.lib.pagesizes import letter | |
| from reportlab.pdfgen import canvas | |
| import json | |
| def create_docx(content: Dict, path: str) -> None: | |
| doc = Document() | |
| doc.add_heading(content.get("name", "Candidate"), level=1) | |
| doc.add_paragraph(content.get("summary", "")) | |
| doc.add_heading("Skills", level=2) | |
| for s in content.get("skills", []): | |
| doc.add_paragraph(s, style="List Bullet") | |
| doc.add_heading("Experience", level=2) | |
| for e in content.get("experiences", []): | |
| doc.add_paragraph(f"{e.get('role','')} — {e.get('company','')} ({e.get('period','')})", style="List Number") | |
| doc.add_paragraph(e.get("details", "")) | |
| doc.save(path) | |
| def create_pdf(content: Dict, path: str) -> None: | |
| c = canvas.Canvas(path, pagesize=letter) | |
| width, height = letter | |
| margin = 72 | |
| y = height - margin | |
| c.setFont("Helvetica-Bold", 18) | |
| c.drawString(margin, y, content.get("name", "Candidate")) | |
| y -= 24 | |
| c.setFont("Helvetica", 11) | |
| for line in content.get("summary", "").splitlines(): | |
| c.drawString(margin, y, line) | |
| y -= 14 | |
| if y < margin: | |
| c.showPage() | |
| y = height - margin | |
| y -= 6 | |
| c.setFont("Helvetica-Bold", 14) | |
| c.drawString(margin, y, "Skills") | |
| y -= 18 | |
| c.setFont("Helvetica", 11) | |
| for s in content.get("skills", []): | |
| c.drawString(margin + 8, y, f"• {s}") | |
| y -= 14 | |
| if y < margin: | |
| c.showPage() | |
| y = height - margin | |
| y -= 6 | |
| c.setFont("Helvetica-Bold", 14) | |
| c.drawString(margin, y, "Experience") | |
| y -= 18 | |
| c.setFont("Helvetica", 11) | |
| for e in content.get("experiences", []): | |
| c.drawString(margin + 8, y, f"{e.get('role','')} — {e.get('company','')} ({e.get('period','')})") | |
| y -= 14 | |
| for line in e.get("details", "").splitlines(): | |
| c.drawString(margin + 12, y, line) | |
| y -= 14 | |
| if y < margin: | |
| c.showPage() | |
| y = height - margin | |
| y -= 8 | |
| if y < margin: | |
| c.showPage() | |
| y = height - margin | |
| c.save() | |
| def generate_cv_content(llm_output: str) -> Dict: | |
| """This function is no longer used in the new POC""" | |
| # This function is retained for backward compatibility but is no longer | |
| # called by app.py in the new POC. | |
| return json.loads(llm_output) |