Extract text from image files within Directus Files with this custom operation, using Clarifai.
Speaker 0: The Directus AI text extraction operation will do exactly that. You feed it an image and it will extract text from that image. You can then do whatever you want with it, but in today's example, we're going to save the extracted text to the file description. And we and we're going to do this based on an event hook, a non blocking event hook whenever a file is uploaded. Now we're gonna not set up any extra configuration, but in the real, you would probably want a condition that, says this has to be an image file.
Right now, it will trigger on every file, and the documentation of this extension will show you how to do that. So then we are gonna just go straight away and we are going to use the AI text extraction operation. And you have to provide your Clarify access token, which I made earlier, and provide a direct file URL. So your full director's project URL slash assets and then slash trigger dot key. So that is the file ID that has just been uploaded that has triggered this whole flow to actually begin.
And this will return a couple of things, it will return the overall text, but it will also return different bounding boxes, so you can say, hey, only give me the text maybe in the top left or stuff like that, but we're gonna just take that overall summary, and we're gonna save it back to the image. So we are going to update the Directus files core collection, and we are going to update specifically the item whose upload started this whole thing, and we are going to set the description to last dot text, so that is the value from this is a is an object, text is a property within it, and that is the entire setup of the AI text extraction operation. Very nifty. So let's, try this out. Let's go to our file library here and let's upload a new file.
Just moments later we can go in and we can see right here the description has been filled in. Now probably a very fair point the AI is not perfect and you'll see here finance manager. The f is missing, but it's not done a bad job. Perhaps in your real workflows, you'll want a a step of human intervention. This will still save loads of time for stuff like business cards, for written documents, for receipts and invoices, but do always make sure that you're checking the output is exactly what you need it to be.
But that is the, the rundown of how the AI text extraction operation works. Hope you found this interesting, and I'll see you in the next video.