1
00:00:00,160 --> 00:00:06,920
And here we are in cursor and going into week eight and going into day five, we get day five.
我们现在处于光标位置，进入第八周，进入第五天，我们得到了第五天。

2
00:00:07,280 --> 00:00:08,560
How did we get here so fast.
我们怎么这么快就到了这里。

3
00:00:08,800 --> 00:00:09,720
All right.
好的。

4
00:00:10,000 --> 00:00:12,240
So it's now time.
所以现在是时候了。

5
00:00:12,240 --> 00:00:15,640
The final step building the user interface.
构建用户界面的最后一步。

6
00:00:15,640 --> 00:00:22,000
And along with that, another uh, Python module that is going to help us out that I will introduce
除此之外，另一个呃，Python 模块将帮助我们解决这个问题，我将介绍它

7
00:00:22,000 --> 00:00:23,440
for you in just a second.
只需一秒钟即可为您服务。

8
00:00:23,680 --> 00:00:29,160
So first of all, that great line import gradio as G.
首先，那条伟大的线将 gradio 导入为 G。

9
00:00:30,040 --> 00:00:34,920
And then this from deal agent framework import deal agent framework.
然后从交易代理框架导入交易代理框架。

10
00:00:34,920 --> 00:00:35,360
What is that?
那是什么？

11
00:00:35,360 --> 00:00:37,440
I told you we weren't going to use any frameworks.
我告诉过你我们不会使用任何框架。

12
00:00:37,440 --> 00:00:38,800
So what is this exactly.
那么这到底是什么。

13
00:00:38,960 --> 00:00:42,600
And then we're bringing in some of the classes we looked at before from deals.
然后我们引入了我们之前从交易中看到的一些课程。

14
00:00:42,720 --> 00:00:43,280
Okay.
好的。

15
00:00:43,320 --> 00:00:48,400
So so with that before before we go further, I want to quickly show you what is in this deal agent
因此，在我们进一步讨论之前，我想快速向您展示该交易代理的内容

16
00:00:48,400 --> 00:00:49,400
framework thing.
框架的东西。

17
00:00:49,560 --> 00:00:50,480
So here it is.
所以就是这样。

18
00:00:50,480 --> 00:00:52,720
Here is the module deal agent framework.
这是模块交易代理框架。

19
00:00:52,720 --> 00:00:57,280
And it's really just the kind of glue that goes around everything.
它确实是一种可以粘在所有东西上的胶水。

20
00:00:57,480 --> 00:01:03,900
Uh, and it's just sort of to take us out of the notebook construct with just one little bit of extra
呃，这只是让我们摆脱笔记本结构，只需一点点额外的东西

21
00:01:03,900 --> 00:01:04,460
functionality.
功能。

22
00:01:04,460 --> 00:01:08,940
So first of all, it has something that sets up logging and does that properly.
首先，它有一些可以设置日志记录并正确执行此操作的功能。

23
00:01:08,940 --> 00:01:11,340
And this is the class deal agent framework.
这就是类交易代理框架。

24
00:01:11,500 --> 00:01:14,140
Um, I've added something called memory.
嗯，我添加了一个叫做内存的东西。

25
00:01:14,380 --> 00:01:16,620
And that sounds like it's something very fancy.
这听起来像是一件非常奇特的事情。

26
00:01:16,620 --> 00:01:21,180
Whenever you hear of memory it sounds like this is very something very clever, ingenious.
每当你听到记忆时，你都会觉得这是一个非常聪明、巧妙的东西。

27
00:01:21,380 --> 00:01:26,620
But it's typically just talking about loading and saving something from disk.
但它通常只是谈论从磁盘加载和保存某些内容。

28
00:01:26,620 --> 00:01:32,300
In some situations, memory is a is a tool that you give an agent so that it can look things up in memory.
在某些情况下，内存是您为代理提供的一种工具，以便它可以在内存中查找内容。

29
00:01:32,300 --> 00:01:35,060
In other cases, it's just something that you'll shove in the prompt.
在其他情况下，您只需将其放入提示中即可。

30
00:01:35,060 --> 00:01:40,500
So make sure that it knows about the prior conversation or to to know about deals that it surfaced in
因此，请确保它了解之前的对话或了解其出现的交易

31
00:01:40,500 --> 00:01:41,020
the past.
过去。

32
00:01:41,340 --> 00:01:42,780
In that case, that's what we're doing here.
在这种情况下，这就是我们在这里所做的。

33
00:01:42,780 --> 00:01:46,780
So I've got a function read memory and a function write memory.
所以我有一个函数读取内存和一个函数写入内存。

34
00:01:46,780 --> 00:01:54,700
And that quite literally reads and writes from a JSON file called memory and memory JSON.
从字面上看，它是从一个名为内存和内存 JSON 的 JSON 文件中读取和写入。

35
00:01:54,700 --> 00:01:55,740
I've clicked on here.
我点击了这里。

36
00:01:55,780 --> 00:02:00,580
It just has a bunch of JSON to describe prior deals that have been surfaced.
它只有一堆 JSON 来描述之前已经出现的交易。

37
00:02:00,580 --> 00:02:05,900
In fact, because our deals are all pedantic objects, it simply writes those pedantic objects to JSON
事实上，因为我们的交易都是迂腐的对象，所以它只是将这些迂腐的对象写入 JSON

38
00:02:06,000 --> 00:02:07,240
and into this file.
并进入这个文件。

39
00:02:07,240 --> 00:02:09,000
And that's why the code is so light.
这就是代码如此简单的原因。

40
00:02:09,040 --> 00:02:11,720
That's what read memory and write memory does.
这就是读内存和写内存的作用。

41
00:02:11,880 --> 00:02:16,560
And there's also a class method reset memory that will put it back to just the first two items.
还有一个类方法重置内存，可以将其恢复到前两项。

42
00:02:16,560 --> 00:02:18,520
So there's something a little in there.
所以里面有一些东西。

43
00:02:18,560 --> 00:02:20,320
There's a log function.
有日志功能。

44
00:02:20,320 --> 00:02:26,440
And then there's there's a run function that kicks things off and gets everything up and running.
然后有一个运行函数来启动并让一切启动并运行。

45
00:02:26,680 --> 00:02:29,440
So this is this is what we have.
这就是我们所拥有的。

46
00:02:29,720 --> 00:02:36,480
Uh, and with that I am now going to, uh, to, to go back to the code so that we can, we can get
呃，现在我要，呃，回到代码，这样我们就可以，我们可以得到

47
00:02:36,480 --> 00:02:37,520
this thing running.
这件事正在运行。

48
00:02:37,720 --> 00:02:38,160
Okay.
好的。

49
00:02:38,200 --> 00:02:43,640
So we're going to do these imports, we're importing Gradio and we're creating this deal agent framework
因此，我们将进行这些导入，导入 Gradio，并创建这个交易代理框架

50
00:02:43,640 --> 00:02:44,440
object.
目的。

51
00:02:44,840 --> 00:02:46,680
Um, all right.
嗯，好吧。

52
00:02:46,720 --> 00:02:50,760
Now the next thing I'm going to do is create a little gradio app.
现在我要做的下一件事是创建一个小渐变应用程序。

53
00:02:50,920 --> 00:02:53,120
And, you know, this isn't a Gradio course.
而且，你知道，这不是普通课程。

54
00:02:53,120 --> 00:02:54,600
So I'm not going to go super deep on it.
所以我不会太深入地讨论它。

55
00:02:54,600 --> 00:03:00,360
But I just want to explain we're using GR blocks, which is when you want to build a Gradio interface
但我只是想解释一下我们正在使用 GR 块，这是当你想要构建 Gradio 界面时

56
00:03:00,360 --> 00:03:04,080
piece by piece, which we did touch on briefly in week two.
我们在第二周确实简要地谈到了这一点。

57
00:03:04,280 --> 00:03:06,320
We're giving it a title, The Price Is Right.
我们给它起了一个标题：价格合适。

58
00:03:06,320 --> 00:03:10,860
We're saying we want to fill the whole width of the interface to not have margins on either side.
我们是说我们想要填充界面的整个宽度，两边都没有边距。

59
00:03:10,860 --> 00:03:13,380
And we're going to have, uh, two, two fields here.
我们这里将有，呃，两个，两个字段。

60
00:03:13,420 --> 00:03:14,340
Markdown.
降价。

61
00:03:14,380 --> 00:03:16,900
The price is right deal hunting agent guy.
价格合适，寻找代理的家伙。

62
00:03:17,220 --> 00:03:19,820
And then a sort of like a subheading.
然后有点像副标题。

63
00:03:20,020 --> 00:03:22,620
Uh, let's just run this to see what happens if I do.
呃，让我们运行一下，看看如果我这样做会发生什么。

64
00:03:22,620 --> 00:03:25,900
So, uh, when I run this, it pops up a screen.
所以，呃，当我运行这个时，它会弹出一个屏幕。

65
00:03:25,940 --> 00:03:27,100
The price is right here.
价格就在这里。

66
00:03:27,100 --> 00:03:33,940
It is a nice gradient UI with, with the with all the usual stuff on an empty screen.
这是一个很好的渐变用户界面，所有常用的东西都在空屏幕上。

67
00:03:33,940 --> 00:03:35,740
Ready for some action.
准备采取一些行动。

68
00:03:35,940 --> 00:03:36,500
Okay.
好的。

69
00:03:36,860 --> 00:03:37,540
All right.
好的。

70
00:03:37,540 --> 00:03:43,380
So let's go back to the code again and let me show you the next step in this UI.
因此，让我们再次回到代码，让我向您展示此 UI 中的下一步。

71
00:03:43,540 --> 00:03:46,220
So we're going to create this deal agent framework.
所以我们将创建这个交易代理框架。

72
00:03:46,220 --> 00:03:47,540
We're going to have that running.
我们将继续运行。

73
00:03:47,820 --> 00:03:52,620
And meanwhile we're going to uh just just try and build out the user interface a little bit more.
与此同时，我们将尝试构建更多的用户界面。

74
00:03:52,660 --> 00:03:58,660
I'm adding in a table which is called a data frame, a table with description, price estimate, discount
我添加了一个称为数据框的表，该表包含描述、价格估算、折扣

75
00:03:58,700 --> 00:03:59,340
URL.
网址。

76
00:03:59,620 --> 00:04:05,100
I'm also going to set up some some initial dummy objects, a deal which is going to have a description
我还将设置一些初始虚拟对象，该交易将有一个描述

77
00:04:05,100 --> 00:04:06,700
example description.
示例描述。

78
00:04:06,980 --> 00:04:10,860
And you know I'm using these things called Gradio callbacks.
你知道我正在使用这些称为“Gradio 回调”的东西。

79
00:04:11,040 --> 00:04:18,600
This callback means when the user interface is loaded, I want you to call this function get table that's
这个回调意味着当用户界面加载时，我希望你调用这个函数获取表

80
00:04:18,600 --> 00:04:19,560
written right here.
就写在这里。

81
00:04:19,800 --> 00:04:25,240
Give it as the inputs, the current deals that I know about and whatever comes out of it.
将其作为输入，我所了解的当前交易以及由此产生的任何结果。

82
00:04:25,280 --> 00:04:27,960
Connect that to this this gradio table.
将其连接到这个渐变表。

83
00:04:28,000 --> 00:04:28,600
All right.
好的。

84
00:04:28,600 --> 00:04:32,520
So this may have been a bit abstract for you, but it will come real when I run it.
所以这对你来说可能有点抽象，但当我运行它时它就会变成现实。

85
00:04:32,520 --> 00:04:36,280
You see that the deal agent framework runs, which brings up lots of stuff.
您会看到交易代理框架正在运行，这会带来很多东西。

86
00:04:36,280 --> 00:04:41,160
Then the UI appears and there's a dummy table with an example item in there.
然后出现 UI，并且有一个虚拟表，其中包含示例项目。

87
00:04:41,200 --> 00:04:45,880
We're starting to see the beginnings of a user interface okay.
我们开始看到用户界面的雏形了。

88
00:04:46,400 --> 00:04:55,280
And now and now I have put this user interface into a Python module and it is called Price is right.py.
现在，我已将此用户界面放入 Python 模块中，并将其命名为 Price is right.py。

89
00:04:55,320 --> 00:04:56,440
Let's take a look at it.
我们来看一下。

90
00:04:56,480 --> 00:05:02,920
It's it's got a bit more I've got some, some funky stuff to deal with with how it's going to uh, collect
它还有更多一些我还有一些一些时髦的东西来处理它如何收集

91
00:05:02,960 --> 00:05:07,280
the logs, anything that's written to the log and display it in Gradio.
日志，写入日志的任何内容并将其显示在 Gradio 中。

92
00:05:07,280 --> 00:05:11,160
And this is a little bit janky, but but otherwise it's all fine.
这有点笨拙，但除此之外一切都很好。

93
00:05:11,280 --> 00:05:18,060
It's it's it's pretty Boilerplate stuff that can be a bit wordy, but I'm making it so that it shows
它是非常样板的东西，可能有点罗嗦，但我这样做是为了让它显示

94
00:05:18,060 --> 00:05:20,060
all of the data on the UI.
UI 上的所有数据。

95
00:05:20,180 --> 00:05:26,900
And I've also got something built in here that means that it sets up a timer so that every five minutes
我还在这里内置了一些东西，这意味着它会设置一个计时器，以便每五分钟

96
00:05:26,900 --> 00:05:29,900
it will wake up and start things running again.
它会醒来并重新开始运行。

97
00:05:30,060 --> 00:05:30,500
Um.
一。

98
00:05:30,540 --> 00:05:31,060
Meaning?
意义？

99
00:05:31,100 --> 00:05:33,020
Meaning that this will always be running.
这意味着这将永远运行。

100
00:05:33,020 --> 00:05:34,100
Always chugging.
总是嘎吱嘎吱的。

101
00:05:34,260 --> 00:05:34,660
Um.
一。

102
00:05:34,660 --> 00:05:36,740
Always doing some processing.
总是做一些处理。

103
00:05:36,980 --> 00:05:44,700
And again, if I go back to the day five lab, um, first up, I've, uh, remember I have that reset
再说一次，如果我回到第五天的实验室，嗯，首先，我，呃，记得我已经重置了

104
00:05:44,740 --> 00:05:51,100
memory function, a convenient function that is going to delete the memory down to just two recent things
记忆功能，一个方便的功能，可以将记忆删除到最近的两件事

105
00:05:51,100 --> 00:05:54,420
that got surfaced so that we start fresh.
这件事浮出水面，让我们重新开始。

106
00:05:54,620 --> 00:06:03,500
Um, and then the next thing that I can do is kick off the prices right dot pi by doing a UV run.
嗯，接下来我能做的就是通过 UV 运行来启动正确的点 pi 价格。

107
00:06:03,500 --> 00:06:06,900
And that of course is is going to basically do a Python.
当然，这基本上是用 Python 实现的。

108
00:06:06,900 --> 00:06:14,300
It's going to launch that app so that we can see this user interface together and that, that that is
它将启动该应用程序，以便我们可以一起看到这个用户界面，那就是

109
00:06:14,300 --> 00:06:16,740
what we're going to be doing in the next video.
我们将在下一个视频中做什么。
