@@ -45,30 +45,30 @@ def extract_text_from_pdf(file_bytes: BinaryIO) -> str:
4545
4646 # Use context manager for better resource management
4747 text = ""
48-
48+
4949 # Open PDF reader with the buffer
5050 pdf = PdfReader (pdf_buffer )
51-
51+
5252 # Process pages one by one to reduce memory usage
5353 for page in pdf .pages :
5454 # Extract text from the page and append to result
5555 page_text = page .extract_text ()
5656 if page_text :
5757 text += page_text + "\n "
58-
58+
5959 # Close the buffer explicitly
6060 pdf_buffer .close ()
61-
61+
6262 # Force garbage collection to free up memory
6363 gc .collect ()
64-
64+
6565 # Truncate very long resume content to prevent token limits
6666 if len (text ) > MAX_RESUME_CONTENT_LENGTH :
6767 logger .info (f"Truncating resume content from { len (text )} to { MAX_RESUME_CONTENT_LENGTH } chars" )
6868 text = text [:MAX_RESUME_CONTENT_LENGTH ] + "..."
69-
69+
7070 return text
71-
71+
7272 except Exception as e :
7373 logger .error (f"Error reading PDF: { str (e )} " , exc_info = True )
7474 # Clean up resources on error
@@ -363,14 +363,14 @@ def generate_resume_review(resume_content: str, job_description: str, custom_ins
363363 prompt_resume = resume_content [:MAX_RESUME_CONTENT_LENGTH ] + "..."
364364 else :
365365 prompt_resume = resume_content
366-
366+
367367 # Truncate job description if it's very long
368368 if len (job_description ) > MAX_JOB_DESCRIPTION_LENGTH :
369369 logger .info (f"Truncating job description for review from { len (job_description )} to { MAX_JOB_DESCRIPTION_LENGTH } chars" )
370370 prompt_job = job_description [:MAX_JOB_DESCRIPTION_LENGTH ] + "..."
371371 else :
372372 prompt_job = job_description
373-
373+
374374 base_prompt = f"""
375375 You are a professional resume reviewer and career coach. Review this resume against the job description
376376 and provide detailed, actionable feedback to help improve the resume.
@@ -483,7 +483,7 @@ def generate_resume_review(resume_content: str, job_description: str, custom_ins
483483 except json .JSONDecodeError as e :
484484 # Clean up memory on error
485485 gc .collect ()
486-
486+
487487 return {
488488 "success" : False ,
489489 "error" : f"Invalid response format from AI model: { str (e )} " ,
@@ -495,4 +495,4 @@ def generate_resume_review(resume_content: str, job_description: str, custom_ins
495495 except Exception as e :
496496 # Clean up memory on error
497497 gc .collect ()
498- return {"success" : False , "error" : f"Error generating resume review: { str (e )} " }
498+ return {"success" : False , "error" : f"Error generating resume review: { str (e )} " }
0 commit comments