isurulkh commited on
Commit
2710492
1 Parent(s): b268da7

Upload app.py

Browse files
Files changed (1) hide show
  1. app.py +36 -29
app.py CHANGED
@@ -34,35 +34,42 @@ def load_prompt(filename):
34
  return f"Error loading prompt: {e}"
35
 
36
  def process_pdf_and_save_job_desc(pdf_file, job_description):
37
- if not pdf_file:
38
- return None, "No file provided"
39
-
40
- doc = fitz.open(stream=pdf_file, filetype="pdf")
41
-
42
- # Store results in a list and process all pages
43
- json_data = []
44
- images = [] # List to hold images of each page
45
- for page_num in range(len(doc)):
46
- page = doc.load_page(page_num)
47
- pix = page.get_pixmap()
48
- img_bytes = pix.tobytes("png")
49
- image = Image.open(io.BytesIO(img_bytes))
50
- images.append(image)
51
-
52
- # ... Your image processing with the genai model
53
- prompt = load_prompt("prompts/resume_parsing_prompt.txt")
54
- response = model_vision.generate_content([prompt, image])
55
- json_data.append(response.text)
56
-
57
- doc.close()
58
-
59
- # Store data appropriately (consider a list of JSON objects, or a structured dict)
60
- with open(INTERMEDIATE_JSON_PATH, "w") as json_file:
61
- json.dump(json_data, json_file)
62
- with open(INTERMEDIATE_JOB_DESC_PATH, "w") as file:
63
- file.write(job_description)
64
-
65
- return images, json_data # Return the list of images
 
 
 
 
 
 
 
66
 
67
  def display_json():
68
  try:
 
34
  return f"Error loading prompt: {e}"
35
 
36
  def process_pdf_and_save_job_desc(pdf_file, job_description):
37
+ try:
38
+
39
+ if not pdf_file:
40
+ return None, "No file provided"
41
+
42
+ doc = fitz.open(stream=pdf_file, filetype="pdf")
43
+
44
+ # Store results in a list and process all pages
45
+ json_data = []
46
+ images = [] # List to hold images of each page
47
+ for page_num in range(len(doc)):
48
+ page = doc.load_page(page_num)
49
+ pix = page.get_pixmap()
50
+ img_bytes = pix.tobytes("png")
51
+ image = Image.open(io.BytesIO(img_bytes))
52
+ images.append(image)
53
+
54
+ # ... Your image processing with the genai model
55
+ prompt = load_prompt("prompts/resume_parsing_prompt.txt")
56
+ response = model_vision.generate_content([prompt, image])
57
+ json_data.append(response.text)
58
+
59
+ doc.close()
60
+
61
+ # Store data appropriately (consider a list of JSON objects, or a structured dict)
62
+ with open(INTERMEDIATE_JSON_PATH, "w") as json_file:
63
+ json.dump(json_data, json_file)
64
+ with open(INTERMEDIATE_JOB_DESC_PATH, "w") as file:
65
+ file.write(job_description)
66
+
67
+ return images, json_data # Return the list of images
68
+
69
+ except fitz.FitzError as e:
70
+ return None, f"PDF processing error: {e}"
71
+ except Exception as e:
72
+ return None, f"An unexpected error occurred: {e}"
73
 
74
  def display_json():
75
  try: