Alexvatti commited on
Commit
f3efdf4
·
verified ·
1 Parent(s): 7ead369

Update main.py

Browse files
Files changed (1) hide show
  1. main.py +13 -3
main.py CHANGED
@@ -58,7 +58,7 @@ def calculate_duration(start, end):
58
 
59
  def parse_resume_text(text: str) -> dict:
60
  prompt = f"""
61
- Extract structured information from this resume text and return the result as a JSON object with the following keys:
62
  - basics: {{first_name, last_name, gender, emails, phone_numbers, address, total_experience_in_years, profession, summary, skills, has_driving_license}}
63
  - educations
64
  - professional_experiences
@@ -68,10 +68,20 @@ def parse_resume_text(text: str) -> dict:
68
  - references
69
  Resume:
70
  {text}
 
71
  """
72
  result = llm([HumanMessage(content=prompt)])
73
- extracted = json.loads(result.content)
74
-
 
 
 
 
 
 
 
 
 
75
  # Map the old structure to the new one
76
  basics = extracted.get("basics", {})
77
  educations = extracted.get("educations", [])
 
58
 
59
  def parse_resume_text(text: str) -> dict:
60
  prompt = f"""
61
+ Extract structured information from this resume text and return the result in strict JSON format with the following keys:
62
  - basics: {{first_name, last_name, gender, emails, phone_numbers, address, total_experience_in_years, profession, summary, skills, has_driving_license}}
63
  - educations
64
  - professional_experiences
 
68
  - references
69
  Resume:
70
  {text}
71
+ Return ONLY valid JSON, no text, no explanation.
72
  """
73
  result = llm([HumanMessage(content=prompt)])
74
+ response_text = str(result.content).strip()
75
+
76
+ if not response_text:
77
+ raise ValueError("LLM response is empty — cannot parse JSON.")
78
+
79
+ try:
80
+ extracted = json.loads(response_text)
81
+ except json.JSONDecodeError as e:
82
+ print("❌ Failed to decode JSON:", response_text)
83
+ raise e
84
+
85
  # Map the old structure to the new one
86
  basics = extracted.get("basics", {})
87
  educations = extracted.get("educations", [])