Upload app.py
Browse files
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 |
-
|
38 |
-
|
39 |
-
|
40 |
-
|
41 |
-
|
42 |
-
|
43 |
-
|
44 |
-
|
45 |
-
|
46 |
-
|
47 |
-
|
48 |
-
|
49 |
-
|
50 |
-
|
51 |
-
|
52 |
-
|
53 |
-
|
54 |
-
|
55 |
-
|
56 |
-
|
57 |
-
|
58 |
-
|
59 |
-
|
60 |
-
|
61 |
-
|
62 |
-
|
63 |
-
|
64 |
-
|
65 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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:
|