files = sorted(glob.glob("../data/cap_*.jpg"))
len(files), files[:9]
(482,
['../data/cap_2024.09.28_15:59:06_Presidentinlinna.jpg',
'../data/cap_2024.09.28_16:00:11_Presidentinlinna.jpg',
'../data/cap_2024.09.28_16:01:16_Etelasatama.jpg',
'../data/cap_2024.09.28_16:02:21_Etelasatama.jpg',
'../data/cap_2024.09.28_16:05:31_Olympiaterminaali.jpg',
'../data/cap_2024.09.28_16:06:36_Olympiaterminaali.jpg',
'../data/cap_2024.09.28_16:07:41_Torni.jpg',
'../data/cap_2024.09.28_16:09:51_Tuomiokirkko.jpg',
'../data/cap_2024.09.28_16:15:11_Presidentinlinna.jpg'])
source
encode_image
encode_image (fname:str)
encode an image file as base64
base64_image = encode_image(files[0])
base64_image[:9]
response = openai.chat.completions.create(
model="gpt-4o",
messages=[{
"role": "user",
"content": [
{"type": "text", "text": question,},
{
"type": "image_url",
"image_url": {"url": f"data:image/jpeg;base64,{encode_image(files[-1])}", "detail":"high",},
},
],
}],
max_tokens=300,
)
source
ask_gpt4v
ask_gpt4v (fn:str)
ask_gpt4v(files[-1])
info(response)
{'timestamp': '2024-10-30T12:45:22',
'location': 'Tuomiokirkko',
'dimensions': {'width': 1280, 'height': 720},
'buildings': {'number_of_buildings': 15,
'building_height_range': '1-6 stories'},
'vehicles': {'number_of_vehicles': 0},
'waterbodies': {'visible': False},
'street_lights': {'number_of_street_lights': 0},
'people': {'approximate_number': 0},
'lighting': {'time_of_day': 'day', 'artificial_lighting': 'none'},
'visibility': {'clear': True},
'sky': {'visible': True, 'light_conditions': 'daylight'}}