LovnishVerma commited on
Commit
9281337
·
verified ·
1 Parent(s): fc82c0a

Update parser_logic.py

Browse files
Files changed (1) hide show
  1. parser_logic.py +18 -9
parser_logic.py CHANGED
@@ -1,6 +1,5 @@
1
  import os
2
  import json
3
- import re
4
  import logging
5
  import fitz # PyMuPDF
6
  from google import genai
@@ -14,11 +13,11 @@ load_dotenv()
14
 
15
  api_key = os.getenv("GEMINI_API_KEY")
16
  if not api_key:
17
- # Fallback to check if key is empty
18
  raise ValueError("GEMINI_API_KEY is missing from Secrets.")
19
 
20
  client = genai.Client(api_key=api_key)
21
 
 
22
  def extract_text_from_stream(file_bytes: bytes) -> str:
23
  text = ""
24
  try:
@@ -30,22 +29,32 @@ def extract_text_from_stream(file_bytes: bytes) -> str:
30
  raise ValueError("Failed to extract text from PDF.")
31
  return text
32
 
 
33
  def parse_resume_with_ai(resume_text: str) -> dict:
34
  prompt = """
35
- Extract the following data from this resume text:
36
- - name, email, phone, skills (list), and summary.
37
- Return strictly valid JSON.
38
- """
39
-
 
 
 
 
 
 
 
40
  try:
41
  response = client.models.generate_content(
42
- model="gemini-1.5-flash",
43
  contents=prompt + "\n\n" + resume_text[:10000],
44
  config=types.GenerateContentConfig(
45
  response_mime_type="application/json"
46
  )
47
  )
 
48
  return json.loads(response.text)
 
49
  except Exception as e:
50
  logger.error(f"AI Processing Error: {e}")
51
- return {"error": f"AI Processing failed: {str(e)}"}
 
1
  import os
2
  import json
 
3
  import logging
4
  import fitz # PyMuPDF
5
  from google import genai
 
13
 
14
  api_key = os.getenv("GEMINI_API_KEY")
15
  if not api_key:
 
16
  raise ValueError("GEMINI_API_KEY is missing from Secrets.")
17
 
18
  client = genai.Client(api_key=api_key)
19
 
20
+
21
  def extract_text_from_stream(file_bytes: bytes) -> str:
22
  text = ""
23
  try:
 
29
  raise ValueError("Failed to extract text from PDF.")
30
  return text
31
 
32
+
33
  def parse_resume_with_ai(resume_text: str) -> dict:
34
  prompt = """
35
+ Extract the following information from the resume text below.
36
+ Return STRICTLY valid JSON with these fields:
37
+
38
+ {
39
+ "name": "",
40
+ "email": "",
41
+ "phone": "",
42
+ "skills": [],
43
+ "summary": ""
44
+ }
45
+ """
46
+
47
  try:
48
  response = client.models.generate_content(
49
+ model="gemini-pro", # ✅ FIXED MODEL
50
  contents=prompt + "\n\n" + resume_text[:10000],
51
  config=types.GenerateContentConfig(
52
  response_mime_type="application/json"
53
  )
54
  )
55
+
56
  return json.loads(response.text)
57
+
58
  except Exception as e:
59
  logger.error(f"AI Processing Error: {e}")
60
+ return {"error": f"AI Processing failed: {str(e)}"}