File size: 1,125 Bytes
611b67c
 
0508b3e
611b67c
 
 
 
 
 
8630bef
611b67c
 
 
 
 
 
 
8630bef
 
 
 
 
 
611b67c
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
import os
import base64
from tqdm import tqdm

from openai_agent import Agent

agent = Agent("./prompts")

# Function to encode the image
def encode_image_from_path(image_path: str) -> str:
    if not os.path.exists(image_path):
        raise FileNotFoundError(f"Image not found at {image_path}")

    with open(image_path, "rb") as image_file:
        return base64.b64encode(image_file.read()).decode("utf-8")


def encode_image(photo_binary: bytes) -> str:
    return base64.b64encode(photo_binary).decode("utf-8")


def process_agent_predictions(file_path: str, photo_binary: bytes):
    base64_image = encode_image(photo_binary)

    prompts = [
        "built_elements",
        "fauna_identification",
        "human_activity",
        "human_detection",
        "vegetation_detection",
        "water_elements",
    ]

    responses = {}
    for prompt in tqdm(prompts):
        detailed_prompt = agent.read_prompt(prompt)
        response = agent.image_request(
            base64_image, detailed_prompt, max_tokens=300, force_json=True
        )
        responses[prompt] = response.as_json()

    return responses