main() is not included in the file. Should be:
def main():
with Path(filepath).open("rb") as fp:
image_binary = fp.read()
response = requests.post(
PINATA_BASE_URL + endpoint,
files={"file": (filename, image_binary)},
headers=headers,
)
print(response.json())