script to generate image alt text in bulk
Hey guys i need your help with the script below. what it already does: #1 first step list all images url missing alt text #2 use the script and generate alt text #3 i need your help for the third step, i ve not found a way to download images in a csv file and associate each image to its alt text. to use the script: #create a file with a columns urls contaning images urls to describe from openai import OpenAI import pandas as pd # put your chat gpt api below client = OpenAI(api_key="CHATGPT-API") def get_alt_text(img_url): response = client.chat.completions.create( model="gpt-4o-mini", messages=[ { "role": "user", "content": [ {"type": "text", "text": "Show me an alternative with a limitof 125 characters for this image to put it in html . Show the alternative text only."}, { "type": "image_url", "image_url": { "url": img_url, }, }, ], } ], max_tokens=20, ) return response.choices[0].message.content df= pd.read_csv('input.csv') df["alt text"] = df["urls"].apply(get_alt_text) df.to_csv('output.csv')