WEBVTT

00:00.080 --> 00:00.920
Welcome back.

00:00.960 --> 00:05.320
We finished the predict mileage function and the validate features.

00:05.480 --> 00:09.800
Also we finished the car mileage predictor class.

00:09.960 --> 00:14.600
Now let's make use of this class and execute the functions.

00:14.720 --> 00:17.240
Open the car mileage predictor screen.

00:17.240 --> 00:22.720
And inside this composable let's create some variables.

00:23.000 --> 00:30.880
So here val predictor equals remember and car mileage predictor class.

00:31.120 --> 00:33.920
And what we need to pass is a context.

00:33.920 --> 00:37.360
So for that let's create a val app.

00:37.400 --> 00:40.400
Context equals to context.

00:40.560 --> 00:46.440
And if it is not null then go and get the current local context.

00:46.640 --> 00:50.200
Pass it here to the car mileage predictor.

00:50.240 --> 00:56.280
Also we need to create an instance of prediction results bar.

00:56.400 --> 01:01.080
Remember it's a mutable state of float.

01:01.120 --> 01:06.040
We need to get the result as a float and make it null.

01:06.360 --> 01:08.240
Then var is loading.

01:08.280 --> 01:10.360
Check if it is loading or not.

01:10.360 --> 01:20.400
So we need to check if the model is calculating and loading or not, just in case displaying a circular

01:20.400 --> 01:21.840
progress bar or not.

01:21.880 --> 01:27.280
Okay, we have the validation errors and car features.

01:27.320 --> 01:27.800
Okay.

01:27.960 --> 01:30.680
Scroll down to the button.

01:30.680 --> 01:33.000
And here the prediction button.

01:33.000 --> 01:34.560
We need to work here.

01:34.560 --> 01:36.880
Here in the onClick.

01:37.040 --> 01:47.880
We need to start by creating a new variable called validation equals to predictor dot validate features

01:47.880 --> 01:50.960
and pass the car features variable.

01:50.960 --> 01:58.930
So here the predictor is an instance of the predictor car mileage predictor class and validate features

01:58.930 --> 02:04.610
is the function that we use we we created in the previous video.

02:04.650 --> 02:05.210
Okay.

02:05.330 --> 02:12.250
We need to pass a car feature variable I pass the car features mutable state.

02:12.290 --> 02:19.050
Now set the validation errors to validation dot errors.

02:19.170 --> 02:29.250
So get from this function the errors list and store it inside the validation errors variable.

02:29.290 --> 02:34.530
Here, let me check if validation is valid.

02:34.570 --> 02:47.050
I told you that this validation is of type uh validate results and this takes two parameters is valid

02:47.050 --> 02:48.090
and errors.

02:48.250 --> 02:50.850
If it is valid it's a boolean.

02:50.850 --> 02:58.450
No errors go and return true if there is any error, return false.

02:58.770 --> 03:01.850
So if there is, there is no errors.

03:01.890 --> 03:05.930
The validation errors list is empty.

03:06.130 --> 03:09.730
This is the logic get is loading to true.

03:09.930 --> 03:11.050
Set it to true.

03:11.330 --> 03:12.610
Prediction.

03:12.650 --> 03:20.410
A result equals to predict dot, predict mileage and pass the card features and is loading.

03:20.450 --> 03:22.010
Set it to false.

03:22.050 --> 03:28.490
Here we are checking if everything every input is valid.

03:28.810 --> 03:38.530
Then go and set the validation to true and if it is true, go and execute the predict mileage function.

03:38.570 --> 03:46.410
Okay, so we used this function validate features to check for all valid inputs.

03:46.610 --> 03:51.850
If all valid inputs are okay and no errors.

03:52.170 --> 03:57.610
So the that validate results returns as valid to true and errors empty.

03:57.970 --> 04:01.170
Then go and execute this function.

04:01.170 --> 04:05.450
Predict mileage and pass the card features as a parameter.

04:05.490 --> 04:10.290
Okay, this is the logic behind using this function.

04:10.370 --> 04:11.810
Then enabled.

04:11.810 --> 04:20.970
If it is not loading then set it to loading so it's opposite to loading if it is loading.

04:21.210 --> 04:23.530
So disable the button.

04:23.530 --> 04:30.050
If it is not loading anything go and enable this button okay.

04:30.090 --> 04:31.050
Inside it.

04:31.090 --> 04:32.330
What we need to do.

04:32.370 --> 04:41.010
We can set a circular progress indicator for uh for displaying that we are making calculation and the

04:41.010 --> 04:43.370
TensorFlow model is working.

04:43.570 --> 04:45.530
So if is loading.

04:45.730 --> 04:50.490
What we need to do create a circular progress indicator.

04:50.780 --> 04:52.380
Said the modifier.

04:52.380 --> 04:58.380
Set the color and make a spacer ATP text.

04:58.500 --> 05:06.620
Set it to predicting and else if it is not, go and display predict mileage.

05:06.780 --> 05:08.020
Then create.

05:08.020 --> 05:14.540
Outside this button we need to display our predictions result.

05:14.540 --> 05:18.500
So let me create a spacer modifier.

05:18.700 --> 05:21.460
Then the predictions result.

05:21.460 --> 05:30.740
If it is not null, go and create an mpg parameter and pass it to the prediction results card.

05:30.860 --> 05:39.980
Okay, so if there is a prediction result, go and display it in the in the prediction result card.

05:40.060 --> 05:43.980
Okay this is our application.

05:44.180 --> 05:47.780
Now let's test our amazing application.
