Spaces:
Sleeping
Sleeping
| import fitz # PyMuPDF | |
| import pdfplumber | |
| from PIL import Image | |
| import io | |
| def extract_text_from_pdf(pdf_path): | |
| try: | |
| with pdfplumber.open(pdf_path) as pdf: | |
| text = "\n".join([page.extract_text() for page in pdf.pages if page.extract_text()]) | |
| return text | |
| except Exception as e: | |
| return "Failed to extract text from resume." | |
| def extract_image_from_pdf(pdf_path): | |
| try: | |
| doc = fitz.open(pdf_path) | |
| for page in doc: | |
| images = page.get_images(full=True) | |
| for img in images: | |
| xref = img[0] | |
| base_image = doc.extract_image(xref) | |
| image_bytes = base_image["image"] | |
| return Image.open(io.BytesIO(image_bytes)) | |
| return None | |
| except Exception as e: | |
| return None | |
| def load_job_description(path="data/job_desc.txt"): | |
| try: | |
| with open(path, "r", encoding="utf-8") as f: | |
| return f.read() | |
| except FileNotFoundError: | |
| return "No job description found." |