1
00:00:00,080 --> 00:00:05,990
Hello, everyone, and welcome to this new and exciting session in which we are going to deploy our

2
00:00:05,990 --> 00:00:07,580
API to the cloud.

3
00:00:07,610 --> 00:00:15,230
Now, in the previous session we had looked at how to build this API using fast API where we could simply

4
00:00:15,230 --> 00:00:22,670
pass in an image like this and then obtain the output where we we get the emotion that is happy and

5
00:00:22,670 --> 00:00:28,370
we also get the time it takes to produce this output so we could execute that.

6
00:00:28,370 --> 00:00:31,130
And you see we have our result right here.

7
00:00:31,760 --> 00:00:39,440
That said, the platform which I'll be using to deploy our API is Heroku, and Heroku is a platform

8
00:00:39,440 --> 00:00:45,290
as a service that is a pass that enables developers to build, run and operate applications entirely

9
00:00:45,290 --> 00:00:46,270
in the cloud.

10
00:00:46,280 --> 00:00:50,110
So first things first, you could go ahead and sign up.

11
00:00:50,120 --> 00:00:57,380
So you click here, sign up and if you've already signed up, you could go ahead and log in.

12
00:00:57,380 --> 00:01:02,610
So once we've signed up and logged in, we could get back to the code here.

13
00:01:02,610 --> 00:01:05,760
We'll stop this, let's clear that out.

14
00:01:05,760 --> 00:01:09,330
And then now what we'll do is we'll do a pip freeze.

15
00:01:09,330 --> 00:01:11,190
So let's do pip freeze.

16
00:01:11,370 --> 00:01:19,380
And you see that we have this output, which is basically all the different packages we have in our

17
00:01:19,380 --> 00:01:20,790
virtual environment.

18
00:01:20,790 --> 00:01:30,030
So now let's write out or put out all these packages right here in a requirements.txt file.

19
00:01:30,030 --> 00:01:33,560
So we'll do PIP freeze and then we'll say, want to pass?

20
00:01:33,580 --> 00:01:37,980
Send this to our requirements dot txt file.

21
00:01:37,980 --> 00:01:40,710
Now note that we are in this directory.

22
00:01:40,710 --> 00:01:42,810
Emotions detection does this.

23
00:01:42,810 --> 00:01:46,910
So when we do this here you find this requirements.

24
00:01:46,920 --> 00:01:48,390
Let's take this one off.

25
00:01:48,390 --> 00:01:51,690
Did this previously um, move to trash?

26
00:01:51,690 --> 00:02:00,450
Okay, so you find that now we're left with service and we have this requirements dot txt that said,

27
00:02:00,450 --> 00:02:02,730
let's open up this requirements.

28
00:02:02,730 --> 00:02:06,990
You see all the different packages which we installed already.

29
00:02:06,990 --> 00:02:11,640
Now we'll get into OpenCV We have.

30
00:02:11,640 --> 00:02:13,680
OpenCV Well that should be Python.

31
00:02:13,680 --> 00:02:15,810
Let's search for OpenCV.

32
00:02:15,810 --> 00:02:17,670
Okay, so it's OpenCV Python.

33
00:02:17,670 --> 00:02:20,640
And now what we'll do is we'll modify this.

34
00:02:20,640 --> 00:02:27,210
And the reason why we modifying this is because this version of OpenCV right here is one which you could

35
00:02:27,210 --> 00:02:29,610
use even with a desktop application.

36
00:02:29,610 --> 00:02:36,000
But what we need for the cloud is one which is headless, that is one which doesn't contain all the

37
00:02:36,000 --> 00:02:36,480
functions.

38
00:02:36,480 --> 00:02:39,330
It's fairly functions like those of visualization.

39
00:02:39,330 --> 00:02:47,370
Given that what we're doing with OpenCV here is essentially, um, maybe resizing and that's basically

40
00:02:47,370 --> 00:02:47,550
it.

41
00:02:47,550 --> 00:02:51,900
So, uh, we don't need this OpenCV python.

42
00:02:52,470 --> 00:02:56,010
We instead we're going to make use of this OpenCV python headless.

43
00:02:56,010 --> 00:02:56,880
So that's it.

44
00:02:56,910 --> 00:03:04,710
We are going to take this version four point, 2.00.3232.

45
00:03:04,740 --> 00:03:05,250
Okay.

46
00:03:05,250 --> 00:03:10,380
So with that done, we save this file to save.

47
00:03:10,650 --> 00:03:17,450
Well, once we save that as administrator, the next thing we do is we are going to create this proc

48
00:03:17,460 --> 00:03:17,880
file.

49
00:03:17,880 --> 00:03:22,020
So in here we have, well, new file.

50
00:03:22,350 --> 00:03:25,080
We'll call this proc file.

51
00:03:25,080 --> 00:03:25,980
There we go.

52
00:03:26,100 --> 00:03:26,690
See?

53
00:03:27,120 --> 00:03:28,440
Recognizes that already.

54
00:03:28,440 --> 00:03:33,390
And then what we'll do is we're going to paste out essentially what we run.

55
00:03:33,660 --> 00:03:35,940
Um, each time we want to launch our server.

56
00:03:35,940 --> 00:03:38,820
So we have web and that's it.

57
00:03:38,820 --> 00:03:42,690
So here we'll specify number of workers to two and that's it.

58
00:03:42,690 --> 00:03:48,450
So here we have Gunicorn service main app, number of worker set, worker class set, and that's fine.

59
00:03:48,450 --> 00:03:50,160
So let's save this too.

60
00:03:50,160 --> 00:03:54,450
And then we create another file runtime dot txt.

61
00:03:54,810 --> 00:04:00,840
Now this runtime dot txt is essentially going to take this python version.

62
00:04:00,840 --> 00:04:05,880
So we'll copy this and we paste that out here.

63
00:04:05,880 --> 00:04:09,690
So here we have Python and this should be fine.

64
00:04:09,900 --> 00:04:18,210
Now also make sure you include this hyphen before this python version with our proc file already the

65
00:04:18,210 --> 00:04:22,650
requirements dot txt file ready and the runtime dot txt file ready.

66
00:04:22,680 --> 00:04:29,790
We're going to get into the Heroku platform where we'll get right here and click on create new app.

67
00:04:29,790 --> 00:04:34,290
So we want to create a new app and then we're going to give this app a name.

68
00:04:34,290 --> 00:04:42,030
So while this loads, there we go, we're going to call this emotions detection.

69
00:04:43,490 --> 00:04:47,480
Now, we could add or add this to a pipeline or deploy this directly.

70
00:04:47,480 --> 00:04:49,330
So we want to deploy this directly.

71
00:04:49,340 --> 00:04:56,810
We have three options using the Heroku git using or by connecting to GitHub or using the Heroku cli.

72
00:04:57,020 --> 00:04:58,730
So we want to use Heroku git.

73
00:04:58,730 --> 00:05:02,120
And so we're going to follow this simple instructions right here.

74
00:05:02,240 --> 00:05:03,740
It's not very long now.

75
00:05:03,740 --> 00:05:05,390
First and first Heroku login.

76
00:05:05,390 --> 00:05:08,810
So let's get back here.

77
00:05:08,840 --> 00:05:11,210
We have Heroku login.

78
00:05:12,560 --> 00:05:16,580
Now you find that this will work and now.

79
00:05:16,580 --> 00:05:19,340
But you should note that let's let's stop this.

80
00:05:19,370 --> 00:05:25,370
You should note that if you don't have Heroku initially installed, this wouldn't work.

81
00:05:25,370 --> 00:05:34,250
So the first thing you want to do is do a sudo snap install heroku, sudo snap, install heroku before

82
00:05:34,250 --> 00:05:35,690
doing the heroku login.

83
00:05:35,690 --> 00:05:40,670
Now given that I've done that already, I will just do a local login and then that should be fine.

84
00:05:40,670 --> 00:05:43,560
So right here we have heroku login and press.

85
00:05:43,560 --> 00:05:50,670
Any key to open up the browser, press any key and it should be able to login very easily.

86
00:05:52,640 --> 00:05:53,580
There we go.

87
00:05:53,600 --> 00:05:57,770
You click on this link right here, and if you click on that link, you should be able to log in.

88
00:05:57,770 --> 00:06:00,560
So you can see here we have logged in.

89
00:06:00,560 --> 00:06:01,730
So that is it.

90
00:06:01,770 --> 00:06:02,930
We're now logged in.

91
00:06:02,960 --> 00:06:10,600
The next thing we want to do is, um, from here we want to do now is get into our project directory.

92
00:06:10,610 --> 00:06:14,390
So once we get into our project directory, let's zoom this.

93
00:06:14,420 --> 00:06:18,170
We get into our project directory and then from there we do a git init.

94
00:06:18,200 --> 00:06:22,310
Now if you're not familiar with git, you could take a crash course on git.

95
00:06:22,310 --> 00:06:24,920
So you get familiar with all these terms.

96
00:06:24,920 --> 00:06:28,820
So let's get back here and do, let's clear this.

97
00:06:29,930 --> 00:06:31,190
Um clear.

98
00:06:31,520 --> 00:06:33,920
And then we do a git init.

99
00:06:34,370 --> 00:06:35,480
There we go.

100
00:06:35,780 --> 00:06:38,760
See we in this emotions detection directory.

101
00:06:38,780 --> 00:06:43,250
Now once we've done that, you see initialize empty repository in our directory.

102
00:06:43,280 --> 00:06:48,500
Now the next thing we want to do is, um, have this here.

103
00:06:48,530 --> 00:06:49,940
Let's copy this.

104
00:06:49,940 --> 00:06:54,410
And then, um, paste this out here.

105
00:06:54,410 --> 00:06:59,150
So we have this Heroku git remote and then we specify the project name.

106
00:06:59,150 --> 00:07:04,040
Notice how this project name is automatically generated because this is what we put in.

107
00:07:04,480 --> 00:07:06,320
Um, let's get back here.

108
00:07:06,470 --> 00:07:07,460
Run this.

109
00:07:07,460 --> 00:07:09,050
And that should be fine.

110
00:07:09,230 --> 00:07:11,510
So that's what we have now.

111
00:07:11,660 --> 00:07:12,460
Command field.

112
00:07:12,470 --> 00:07:13,820
We told that to.

113
00:07:13,850 --> 00:07:20,930
Well, we command field git remote, fertile, unsafe repository to add an exception for this directory

114
00:07:20,930 --> 00:07:24,380
called git config and that's it.

115
00:07:24,380 --> 00:07:30,620
So what we'll do is now we're going to copy this and then paste out right here.

116
00:07:30,620 --> 00:07:33,110
So there we go.

117
00:07:33,110 --> 00:07:38,180
Let's now get back and run this and this should work.

118
00:07:38,180 --> 00:07:39,470
So that is it.

119
00:07:39,470 --> 00:07:43,810
So set git remote Heroku to this and that's fine.

120
00:07:43,820 --> 00:07:48,380
Now the next step we want to do is deploy the application.

121
00:07:48,380 --> 00:07:53,460
So we have git add, git commit and git push.

122
00:07:53,460 --> 00:07:56,190
So let's go ahead and do git add.

123
00:07:56,220 --> 00:08:00,090
We want to add up all our files.

124
00:08:00,090 --> 00:08:04,920
So pick the dot and then we have let's copy this.

125
00:08:04,920 --> 00:08:11,330
Git commit, um, git commit, make it better, paste it out.

126
00:08:11,340 --> 00:08:25,410
Well let's say our first, first, um, commit of our emotions detection app or well, API.

127
00:08:25,410 --> 00:08:28,320
So this is a string which you could obviously modify.

128
00:08:28,350 --> 00:08:35,760
Now we run that and then now you see we have all this, um, created and then now let's go ahead and

129
00:08:35,760 --> 00:08:38,370
do the git push Heroku master.

130
00:08:38,370 --> 00:08:44,310
So here we have git push Heroku master and this should work.

131
00:08:44,310 --> 00:08:44,910
Fine.

132
00:08:45,750 --> 00:08:50,130
What we get here is this push rejected to emotional detection neural learn.

133
00:08:50,130 --> 00:08:53,970
So let's scroll up and try to understand why we have this problem.

134
00:08:53,970 --> 00:08:59,010
So we told your request at runtime is not available for this stack.

135
00:08:59,010 --> 00:09:09,510
So open this up and then, um, let's try to check out on this different Python versions available for

136
00:09:09,510 --> 00:09:10,650
the stack here.

137
00:09:10,650 --> 00:09:16,170
You could see we have this, um, 3.9.15, which is on all supported stacks.

138
00:09:16,170 --> 00:09:21,510
So let's get back here and then um, a level of the runtime.

139
00:09:21,510 --> 00:09:31,080
Let's, let's take all this off, paste that now save that, save that and then we'll do, um, git

140
00:09:31,080 --> 00:09:35,310
add, um, git commit.

141
00:09:35,340 --> 00:09:51,390
Now what we'll say here is we have um, updated runtime dot txt file with Python version 3.9.15, run

142
00:09:51,390 --> 00:09:55,620
that and then now we're ready to do git push Heroku master once more.

143
00:09:57,330 --> 00:10:02,140
We still get another error right here where we told that um.

144
00:10:02,220 --> 00:10:05,850
No matching distribution found for OpenCV Python headless.

145
00:10:06,120 --> 00:10:12,600
So now we're going to take off this version and then we do the git push one more time.

146
00:10:13,080 --> 00:10:18,330
Once they get pushed down, you see that we now have this release and here is our link.

147
00:10:18,330 --> 00:10:19,860
So let's click on this.

148
00:10:19,860 --> 00:10:23,280
We open up and there we go.

149
00:10:23,310 --> 00:10:25,140
See, we have Hello World.

150
00:10:25,140 --> 00:10:27,990
So this is what we have online now.

151
00:10:27,990 --> 00:10:35,850
And we could go, um, docs and we check out on our swagger UI.

152
00:10:35,880 --> 00:10:41,280
So let's reduce this and let's try this out.

153
00:10:41,310 --> 00:10:43,250
See, we're trying this out online.

154
00:10:43,260 --> 00:10:45,300
We've deployed this on the cloud.

155
00:10:45,330 --> 00:10:47,970
Let's execute and see what we get.

156
00:10:48,000 --> 00:10:48,420
Okay?

157
00:10:48,420 --> 00:10:51,600
So it even takes less time as compared to we.

158
00:10:52,160 --> 00:10:56,000
The PC is taking like 0.23 seconds.

159
00:10:56,000 --> 00:10:58,880
That's about 230 milliseconds.

160
00:10:58,910 --> 00:11:00,590
Let's reduce this so we can see that.

161
00:11:01,520 --> 00:11:04,370
Um, okay, so that's it.

162
00:11:04,370 --> 00:11:09,500
So we see that our model is working, we're able to obtain our outputs.

163
00:11:09,500 --> 00:11:18,080
And then now what we could do is we could actually from here, let's copy this here and then try this

164
00:11:18,080 --> 00:11:19,610
out on Postman.

165
00:11:19,610 --> 00:11:21,200
So there we go.

166
00:11:21,200 --> 00:11:26,420
We have this enter the URL and then we select post request.

167
00:11:26,810 --> 00:11:33,250
Um, well, here we have the body, here we have form data.

168
00:11:33,290 --> 00:11:39,290
Then our key, our key here is going to be image M and then the value.

169
00:11:39,320 --> 00:11:43,370
Given that it's a file, we will now select the file.

170
00:11:43,580 --> 00:11:44,330
There we go.

171
00:11:44,330 --> 00:11:50,240
We have our file selected, click on send and we should get our expected output.

172
00:11:50,240 --> 00:11:57,380
You see here we have happy and time elapsed 230 milliseconds.

173
00:11:57,380 --> 00:11:59,120
So that's what we expect.

174
00:11:59,120 --> 00:12:02,270
You could see from here we have this different timing.

175
00:12:02,270 --> 00:12:09,290
We have the status and we have the time it took for all the different events right here.

176
00:12:10,100 --> 00:12:16,520
And so that's it for the section in which we've deployed our API to the cloud.

177
00:12:16,520 --> 00:12:21,710
And in the next section we are going to carry out load testing on our deployed API.
