And welcome now to the code for our user interface, which we will find in this Python module.
Price is right dot pi.
And this is where we will be looking at particularly the code that constructs the UI behind our product.
And it starts with a few imports.
This very important one to import Gradio.
And this even more important one to import the deal agent framework, which is at the heart of what
we built.
Uh, and then it defines a class app.
And if I scroll to the bottom, you'll see that at the bottom it calls app dot run.
It creates app and then runs it.
And what does that involve creating?
It does very little.
It just sets an empty variable for agent framework.
The juice the meat is in the run uh method.
And that of course creates a user interface using Gradio more advanced construct of great blocks with
the Price is Right.
Um, and then what you see here is some code that's quite similar to the code that we've already looked
at before.
In fact, the user interface part of it right here is identical.
We have some rows with some titles.
Um, and then we include our data frame.
It has description price estimate discount and Earl as the columns.
And it's set up and assigned to something called opportunities data frame just as before.
Uh, the only thing that's changed is what's coming right afterwards.
So here we go.
This is the new stuff in this file.
There is, uh, a UI dot load.
So this is again where we tell Gradio.
When you load, we want you to carry out a particular, uh, instruction.
And we specify that using the standard format for gradio, where you start with the name of the function,
it should call the inputs and the outputs.
And in this case we're saying we want you to call the function called start.
There are no inputs to this function.
And whatever it returns, we want you to hook that up to the opportunities data frame.
And that means we expect it to return some information that is suitable to be put into a table.
So that's what we expect to see from a function start.
And then we're going to create another Gradio UI component called a GR dot timer.
And that is something which which does some timing.
It is in fact a UI component which is invisible.
It's something that runs behind the scenes and it will wake up every 60s.
And what does it do every 60s well, you have to tell Gradio what it should do.
And the way you tell Gradio is by calling timer, dot, tick.
And when you do that, you provide the information to Gradio again using the standard Gradio structure
standard approach.
You tell it the function that will be called.
In this case I say go.
You give it the inputs, there aren't any and the outputs, whatever go returns should be put into the
opportunities data frame.
Again, simple as that.
The select method here that's that we call is exactly the same as before.
It's another thing that hasn't changed.
It's not exactly the same.
It's changed a tiny bit, but it's basically the same.
And it ends with a call to the agent framework planner messenger alert, alert about the opportunity.
So you probably noticed the small the small change there.
It's going to do a full alert.
Uh, and all that remains is for us to go and look at the two functions we're expecting to see start
and go.
And at the top of the display you will find is indeed start and go the two functions in question.
And if we look at them, let's start with start.
What start does is it creates a new instance of the deal agent framework.
The key object that controls our whole framework.
It instantiates it, and it then asks it for its memory of what opportunities does it have.
And then it calls this function table for with these opportunities and it returns that table.
So what does table four do.
Table four is this tiny function up here.
So table four takes opportunities.
And then you remember opportunities if we go in here.
Opportunities are these objects here.
That is exactly what gets stored in the memory of the agent framework contains a deal an estimate and
a discount.
That is an opportunity.
So we go back to week eight.
So um, the this function converts an opportunity object into just a list of strings.
A list of lists of strings with the description, the price, the estimate, the discount, the URL
exactly the type, the structure that's needed to slot into the data frame that we have down here.
So again, start just simply creates a deal.
Agent framework.
Looks at its memory, converts that into strings and returns it and go.
Which is the thing that gets called every 60s.
Go is going to do something very, very similar.
You'll see it looks very similar.
It just has this one little tiny line added, a tiny little line.
It doesn't do very much.
It does everything.
This is the line that calls run on our agent framework.
It's the thing that we were doing manually before.
It triggers the entire workflow that we have built.
And that's what go does.
And go will be kicked off every 60s by this GR timer so that that is the business of it.
All that remains is to see it working in action.
And so now to see this happening, we're going to go to the launcher and we're going to open a new terminal.
And I'm going to change to my to activate my conda environment with conda activate LMS.
There we go.
And now I can run it by just typing Python price is right.
Dot py should be as simple as that.
Let's see a bit of a drum roll.
And 321.
Here we go.
There's a pause while it thinks for a second and bam!
Up comes the price is right and there's more work going on.
And here we see right in front of us.
What we're looking at, of course, is the memory.
We're looking at the opportunities that it's come up with.
And we can scroll down and see this bottom item here.
I do believe that that is the item that was just surfaced to us most recently, when we ran it from
the command line before.
Um, and of course it then puts it into its memory.
So we're seeing the items that have been surfaced here.
And if I go back over to, uh, the command line, we'll see, of course, that it initialized, it
set things up, it got itself ready, uh, and it's now going to be sitting in a loop so that, uh,
it's going to be waiting for the agent to tick.
And after a minute, it will kick off and launch and hopefully you're doing the same thing.
You've opened this up, you're running it, you're going to give this a try.
And like me, you will then see it run.
And I will go to the next lecture where we will take a look at the outcome.
Uh, I will see you there.