File size: 1,343 Bytes
716138f |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 |
import argparse
import json
import os
import pathlib
from google.genai import types
import PIL.Image
from schema import DeveloperResume
from prompts import parsing_prompts
from logger import logger
def parse_pdf(pdf_path: str, genai_client) -> dict:
filepath = pathlib.Path(pdf_path)
logger.info(f"Parsing PDF file: {filepath}")
response = genai_client.models.generate_content(
model="gemini-1.5-flash",
contents=[
types.Part.from_bytes(
data=filepath.read_bytes(),
mime_type="application/pdf",
),
parsing_prompts,
],
config={
"response_mime_type": "application/json",
'response_schema': DeveloperResume,
},
)
json_data = json.loads(response.text)
return json_data
def parse_image(image_path:str, genai_client) -> dict:
image = PIL.Image.open(image_path)
logger.info(f"Parsing image file: {image_path}")
response = genai_client.models.generate_content(
model="gemini-1.5-flash",
contents=[
image,
parsing_prompts,
],
config={
"response_mime_type": "application/json",
'response_schema': DeveloperResume,
},
)
json_data = json.loads(response.text)
return json_data |