[00:01] show you the example of how to use Python inside of Laravel project because Python is stronger, for example, for data analysis, AI operations, stuff like [00:13] image analysis like in this case. For example, if you want to perform OCR, so reading the text from the image, you can run Python script using Pytesseract in this case inside of Laravel project with a queued job and processes. Let me show [00:29] you how it works. So, I've built this Laravel and Filament project demo where I upload the image and then when I hit create, a queued job will be executed. So, this is Q work running in the background and look what happens. I [00:43] create, then I'm redirected to view page and then there's a poll operation every second which when the job is completed has detected text here. So, I can zoom in. This is the image and this is the text that was detected by Pytesseract. [01:00] would see that in full. So, this is the text and this is very simple Python script with default Pytesseract in Python. So, that's why it has some issues. It's not ideal, but this is not the point of this video. The point is to [01:14] have this result JSON which comes from Python into Laravel and into the Python into Laravel and into the database and how does it all work? So, there's analyze image job which was executed in half a second which called [01:29] the Python script that you already saw. But how exactly? So, in Filament or it could be Laravel controller if you don't use Filament, you can have a queued job dispatched. So, you have a new image analysis in this case and you have [01:43] analysis in this case and you have record ID and then dispatch the job into the queue also after committing the database operations. Inside that job, let me probably zoom that in. This is a typical Laravel job with shoot queue and [01:57] ID passed in the constructor and in the handle we have data coming from the database updating the status and then try catch and then try catch users analyze method from analyzer python image analyzer class which is a service. [02:13] So this is a separation of concern to have a separate service but inside of that analyze this is probably the main thing process. So we have python binary which is python 3 or python then the path to the script and then the path to [02:28] the image that should be processed. And part of that comes from config so config services this is python binary this is analyzer script which is the same that you saw a minute ago and then the image path is resolved image path which then [02:43] depends on filament or wherever that image lands from the form. And then the result of that process is output which then is processed with JSON decode and [02:55] returned after a few more checks from that service function. Then inside of that queued job we have the analysis result which then performs the database update. And then to show the data we have in filament image analysis info [03:10] list but again in Laravel controller it could be a view page and here we have poll. So in this case it's calling the server every what every 3 seconds by default or it could be configurable as well. So while the status is pending [03:25] every 3 seconds it will refresh the data or try to refresh the data until the status changes. Also important in that image analyzer process there's timeout of 30 seconds. So if something goes wrong with python it will timeout in 30 [03:41] seconds and then queued job would be restarted depending on your settings with the queue. Now what is this process if you haven't worked with that before? So this is the Laravel documentation page about processes. This is not a new [03:55] feature. I found it randomly, for example, in Twilio blog article from 2023. So, it existed for 3 days at least. Even if you haven't used that, it uses Symfony process component. So, Laravel has its own process kind of a [04:11] wrapper, which may be faked for testing and has a few more features on top of Symfony. But, basically, you just run the process like this. And then you have the output and other things. And you can [04:25] scrolling, as you can see, indicator is pretty small. So, there are a lot of things that you can configure and then have more granular result. But, I just wanted to show you the main mechanism. So, quick recap, from Laravel controller [04:40] or filament, you dispatch a job. Then that job, with a service or without the that job, with a service or without the service, calls the Python script with process class. And then you get the data, you JSON decode it, for example, [04:53] if it's a JSON, and then update the database. Of course, for that you need to have Python installed and configured on the same machine, on the same server. But, this is kind of outside of this video. What I wanted to tell is that [05:06] Laravel isn't really limited to Laravel only because for many operations, especially in the age of AI, Python is more suitable candidate to deliver the code. What do you guys think about this demo? Do you have any use case similar [05:20] to that? Do you have Python scripts running on the server alongside Laravel application? So, what are the use case? We can discuss, as usual, in the comments below. And finally, I want to remind about a free weekly newsletter [05:33] that I send on Laravel daily. So, 6,000 subscribers, and you can join them for Thursday weekly news of Laravel core releases, packages, new packages, new products. Because in the age of AI, people are releasing more and more new [05:48] stuff or new versions of older stuff. So, you can read past issues here, for example, and subscribe for free. The link will be in the description below. That's it for this time, and see you guys in other videos.