WEBVTT 00:00.680 --> 00:08.180 And welcome now to the code for our user interface, which we will find in this Python module. 00:08.180 --> 00:10.130 Price is right dot pi. 00:10.130 --> 00:18.860 And this is where we will be looking at particularly the code that constructs the UI behind our product. 00:19.070 --> 00:22.070 And it starts with a few imports. 00:22.190 --> 00:24.110 This very important one to import Gradio. 00:24.110 --> 00:29.210 And this even more important one to import the deal agent framework, which is at the heart of what 00:29.210 --> 00:29.900 we built. 00:30.230 --> 00:33.440 Uh, and then it defines a class app. 00:33.440 --> 00:39.080 And if I scroll to the bottom, you'll see that at the bottom it calls app dot run. 00:39.110 --> 00:41.270 It creates app and then runs it. 00:41.270 --> 00:43.250 And what does that involve creating? 00:43.250 --> 00:44.240 It does very little. 00:44.240 --> 00:47.420 It just sets an empty variable for agent framework. 00:47.450 --> 00:51.260 The juice the meat is in the run uh method. 00:51.260 --> 00:59.200 And that of course creates a user interface using Gradio more advanced construct of great blocks with 00:59.200 --> 01:00.280 the Price is Right. 01:00.610 --> 01:05.590 Um, and then what you see here is some code that's quite similar to the code that we've already looked 01:05.590 --> 01:06.250 at before. 01:06.280 --> 01:10.480 In fact, the user interface part of it right here is identical. 01:10.480 --> 01:14.020 We have some rows with some titles. 01:14.020 --> 01:17.890 Um, and then we include our data frame. 01:17.890 --> 01:22.630 It has description price estimate discount and Earl as the columns. 01:22.630 --> 01:28.480 And it's set up and assigned to something called opportunities data frame just as before. 01:28.750 --> 01:33.040 Uh, the only thing that's changed is what's coming right afterwards. 01:33.040 --> 01:34.810 So here we go. 01:34.840 --> 01:37.630 This is the new stuff in this file. 01:37.630 --> 01:40.780 There is, uh, a UI dot load. 01:40.780 --> 01:43.660 So this is again where we tell Gradio. 01:43.690 --> 01:48.310 When you load, we want you to carry out a particular, uh, instruction. 01:48.310 --> 01:54.060 And we specify that using the standard format for gradio, where you start with the name of the function, 01:54.060 --> 01:56.970 it should call the inputs and the outputs. 01:56.970 --> 02:00.690 And in this case we're saying we want you to call the function called start. 02:00.720 --> 02:02.700 There are no inputs to this function. 02:02.700 --> 02:07.890 And whatever it returns, we want you to hook that up to the opportunities data frame. 02:07.890 --> 02:13.500 And that means we expect it to return some information that is suitable to be put into a table. 02:13.500 --> 02:16.860 So that's what we expect to see from a function start. 02:17.310 --> 02:23.130 And then we're going to create another Gradio UI component called a GR dot timer. 02:23.130 --> 02:26.160 And that is something which which does some timing. 02:26.160 --> 02:29.100 It is in fact a UI component which is invisible. 02:29.400 --> 02:35.160 It's something that runs behind the scenes and it will wake up every 60s. 02:35.160 --> 02:38.580 And what does it do every 60s well, you have to tell Gradio what it should do. 02:38.580 --> 02:42.480 And the way you tell Gradio is by calling timer, dot, tick. 02:42.480 --> 02:48.870 And when you do that, you provide the information to Gradio again using the standard Gradio structure 02:48.870 --> 02:50.060 standard approach. 02:50.060 --> 02:52.220 You tell it the function that will be called. 02:52.220 --> 02:54.350 In this case I say go. 02:54.380 --> 03:01.610 You give it the inputs, there aren't any and the outputs, whatever go returns should be put into the 03:01.610 --> 03:03.080 opportunities data frame. 03:03.080 --> 03:05.300 Again, simple as that. 03:05.330 --> 03:11.180 The select method here that's that we call is exactly the same as before. 03:11.180 --> 03:12.440 It's another thing that hasn't changed. 03:12.440 --> 03:13.550 It's not exactly the same. 03:13.550 --> 03:16.490 It's changed a tiny bit, but it's basically the same. 03:16.550 --> 03:23.570 And it ends with a call to the agent framework planner messenger alert, alert about the opportunity. 03:23.840 --> 03:27.290 So you probably noticed the small the small change there. 03:27.290 --> 03:29.360 It's going to do a full alert. 03:29.750 --> 03:36.410 Uh, and all that remains is for us to go and look at the two functions we're expecting to see start 03:36.410 --> 03:37.130 and go. 03:37.130 --> 03:44.810 And at the top of the display you will find is indeed start and go the two functions in question. 03:44.820 --> 03:48.030 And if we look at them, let's start with start. 03:48.060 --> 03:53.280 What start does is it creates a new instance of the deal agent framework. 03:53.310 --> 03:56.610 The key object that controls our whole framework. 03:56.940 --> 04:02.460 It instantiates it, and it then asks it for its memory of what opportunities does it have. 04:02.460 --> 04:08.430 And then it calls this function table for with these opportunities and it returns that table. 04:08.460 --> 04:09.930 So what does table four do. 04:09.960 --> 04:12.360 Table four is this tiny function up here. 04:12.900 --> 04:15.870 So table four takes opportunities. 04:15.870 --> 04:18.810 And then you remember opportunities if we go in here. 04:18.840 --> 04:23.250 Opportunities are these objects here. 04:23.250 --> 04:29.340 That is exactly what gets stored in the memory of the agent framework contains a deal an estimate and 04:29.340 --> 04:30.000 a discount. 04:30.000 --> 04:31.380 That is an opportunity. 04:31.980 --> 04:34.170 So we go back to week eight. 04:34.440 --> 04:42.530 So um, the this function converts an opportunity object into just a list of strings. 04:42.560 --> 04:47.840 A list of lists of strings with the description, the price, the estimate, the discount, the URL 04:47.840 --> 04:54.860 exactly the type, the structure that's needed to slot into the data frame that we have down here. 04:54.890 --> 04:58.730 So again, start just simply creates a deal. 04:58.730 --> 04:59.480 Agent framework. 04:59.510 --> 05:06.440 Looks at its memory, converts that into strings and returns it and go. 05:06.470 --> 05:09.920 Which is the thing that gets called every 60s. 05:09.950 --> 05:13.160 Go is going to do something very, very similar. 05:13.160 --> 05:14.630 You'll see it looks very similar. 05:14.660 --> 05:18.200 It just has this one little tiny line added, a tiny little line. 05:18.350 --> 05:19.490 It doesn't do very much. 05:19.490 --> 05:20.780 It does everything. 05:20.780 --> 05:25.370 This is the line that calls run on our agent framework. 05:25.370 --> 05:27.950 It's the thing that we were doing manually before. 05:27.950 --> 05:31.610 It triggers the entire workflow that we have built. 05:31.610 --> 05:33.290 And that's what go does. 05:33.320 --> 05:41.800 And go will be kicked off every 60s by this GR timer so that that is the business of it. 05:42.010 --> 05:45.700 All that remains is to see it working in action. 05:45.820 --> 05:52.630 And so now to see this happening, we're going to go to the launcher and we're going to open a new terminal. 05:52.660 --> 05:58.750 And I'm going to change to my to activate my conda environment with conda activate LMS. 05:59.920 --> 06:01.090 There we go. 06:01.090 --> 06:08.020 And now I can run it by just typing Python price is right. 06:08.050 --> 06:10.570 Dot py should be as simple as that. 06:10.600 --> 06:13.390 Let's see a bit of a drum roll. 06:13.420 --> 06:15.220 And 321. 06:15.220 --> 06:16.180 Here we go. 06:18.100 --> 06:23.050 There's a pause while it thinks for a second and bam! 06:23.080 --> 06:27.100 Up comes the price is right and there's more work going on. 06:27.100 --> 06:29.950 And here we see right in front of us. 06:30.250 --> 06:32.200 What we're looking at, of course, is the memory. 06:32.230 --> 06:34.860 We're looking at the opportunities that it's come up with. 06:35.280 --> 06:39.120 And we can scroll down and see this bottom item here. 06:39.120 --> 06:45.180 I do believe that that is the item that was just surfaced to us most recently, when we ran it from 06:45.180 --> 06:46.920 the command line before. 06:47.010 --> 06:49.500 Um, and of course it then puts it into its memory. 06:49.500 --> 06:54.000 So we're seeing the items that have been surfaced here. 06:54.000 --> 07:02.730 And if I go back over to, uh, the command line, we'll see, of course, that it initialized, it 07:02.730 --> 07:09.480 set things up, it got itself ready, uh, and it's now going to be sitting in a loop so that, uh, 07:09.480 --> 07:11.760 it's going to be waiting for the agent to tick. 07:11.790 --> 07:16.590 And after a minute, it will kick off and launch and hopefully you're doing the same thing. 07:16.590 --> 07:19.830 You've opened this up, you're running it, you're going to give this a try. 07:19.830 --> 07:22.590 And like me, you will then see it run. 07:22.590 --> 07:28.980 And I will go to the next lecture where we will take a look at the outcome. 07:29.250 --> 07:30.720 Uh, I will see you there.