Create captions for your images within Directus Files with this custom operation, powered by Clarifai.
Speaker 0: The Directus AI alt text writer will take in an image and provide a description for the image, which you can then save in the description of that image and use in your applications to make them more accessible. So we're gonna set it up today. So, automatically, whenever a new file is uploaded, it will go off and have its description automatically and we'll make this an event based hook. When and we'll make this an event based hook whenever a file is uploaded. Now just to note that here this will trigger on every single file regardless of file type.
I'm gonna leave it like this, but in the real, you would probably want to add a condition that says, hey. Make sure this is an image or, you know, make sure this is in a certain directory. The docs on how to do that are inside of the marketplace listing for this extension, but we won't do that. So, you know, we'll assume every file that's uploaded is going to be an image. So we're gonna jump straight in and we are going to use the AI alt text writer, and this operation uses Clarify.
So we have to provide our access token, and we have to provide a direct full URL. So what we're gonna do there is provide the core URL of our directors project slash assets slash and then a dynamic value here trigger dot key, and that will be the ID of the image or file that has just been uploaded causing this flow to start in the first place. So that will go off, and, honestly, it's pretty straightforward, this one. It just returns a string, which is the description. So we're gonna go straight ahead, and we are going to update data in the Directus files collection, specifically, the item that triggered this flow and we are going to update the description.
And the value will be lost because it just returns the string. That's it. That's how you set up the AI alt text writer. It's really really pleasant and, you know, if you can set this up earlier rather than later you can make sure more of your images actually have alt text written. Let's, let's try it out here.
So I've got this photo from a holiday, I did a few months ago with my friend Nathaniel, and we click into that and you know what not bad. A photograph of 2 men sitting on a bench in front of a sign that says Avenue Ave Ave. Again, do double check these, you know, there is a point where they can you know, where enough, error proneness, can actually cause a degraded experience for people who need this, but it will get you a really long way there. Of course, it was never gonna get that this said Avengers Campus, so I think I'll forgive it this time. So that is how to set up the AI alt text writer operation.
Hope you found this interesting, and I'll see you in the next video.