WEBVTT

00:00.560 --> 00:01.000
Okay.

00:01.040 --> 00:09.080
We're going to use file client locally to send a request to file and run flux to image generation tool.

00:09.120 --> 00:11.880
So first we need to pip install.

00:12.120 --> 00:15.680
I recommend installing it in an environment if you don't already have that.

00:23.080 --> 00:26.480
And then you need to load the environment as well.

00:26.480 --> 00:30.280
We have load env here from dot env.

00:30.320 --> 00:32.280
And then we just run load dot env.

00:32.520 --> 00:34.960
And when you have a dot env file.

00:35.000 --> 00:38.280
So just a file on your computer that's called dot env.

00:38.320 --> 00:48.400
In this local space you would have a file underscore key in their file key equals the API key that you

00:48.400 --> 00:49.400
have from here.

00:49.440 --> 00:51.520
So if you run that it's going to tell you true.

00:51.520 --> 00:52.880
This loaded the environment.

00:53.040 --> 00:54.960
And then hopefully you should have your API key.

00:55.000 --> 00:59.440
If you don't have an API key you just need to go to this URL here.

00:59.440 --> 01:02.160
And then you should be able to find find your API key.

01:02.200 --> 01:06.000
Once you create an account and once you have a paid account as well.

01:06.520 --> 01:06.800
All right.

01:06.840 --> 01:08.440
So now let's get into the code.

01:08.800 --> 01:11.200
So we want to import file client.

01:11.500 --> 01:16.540
We want to get the Pil package to get an image.

01:16.740 --> 01:21.940
I want to import requests so we can make the request to get the image afterwards.

01:21.940 --> 01:24.940
And then we also want to get this bytesio as well.

01:24.980 --> 01:26.340
This is for dealing with the image.

01:26.860 --> 01:33.500
But the main thing we do with file is we just submit a prompt and then we submit a model as well.

01:33.500 --> 01:40.020
In this case the prompt is a photo of a rhino dressed suit and tie sitting at a table in a bar with

01:40.020 --> 01:44.060
bar stools, award winning photography, and then this name of the photographer.

01:44.580 --> 01:46.460
And we're going to create the handler.

01:46.460 --> 01:49.580
We're going to go to file client and then submit.

01:49.580 --> 01:51.620
And there's a few different methods that I'll show you.

01:52.180 --> 01:54.860
But then this is the simple way to do it.

01:54.900 --> 01:59.740
We just want to get the result and to do the result we just do handler get.

01:59.740 --> 02:01.460
And then we can print the result.

02:02.540 --> 02:05.660
And let me just show you what that comes back with.

02:16.300 --> 02:18.180
You can see we have an image here.

02:19.020 --> 02:21.220
And there's a width or height.

02:21.670 --> 02:27.110
how much time it took, for example, and the prompt and if we click on this should be able to see the

02:27.110 --> 02:27.550
image.

02:27.550 --> 02:27.910
Here we go.

02:27.910 --> 02:29.510
We have a rhino in a suit.

02:30.070 --> 02:37.550
So in order to get at that image we want to do image URL equals result images.

02:37.550 --> 02:42.750
And then you get the first image because it could come back with multiple if you add that argument in

02:42.790 --> 02:48.190
and then you get the URL of that image, and then you just need to make a request to get the image to

02:48.230 --> 02:49.990
download it as bytes.

02:49.990 --> 02:51.990
And then we can open the image like this.

02:51.990 --> 02:54.510
So if I run that again it's going to run the prompt again.

02:54.990 --> 02:57.030
And then it'll just display the image for us.

02:58.470 --> 02:58.830
Here we go.

02:58.830 --> 03:00.070
So we can see it right here.

03:00.070 --> 03:01.070
So this is a new image.

03:01.070 --> 03:06.430
Every time you run it it's something different unless you use the same seed okay.

03:06.470 --> 03:12.510
Now that we have that we want to function for generating images in general, let's just wrap that and

03:12.510 --> 03:14.910
we'll say call this generate image.

03:14.950 --> 03:16.910
We want to take in a prompt and a model.

03:17.150 --> 03:19.310
And then we're going to do the handler.

03:19.790 --> 03:23.470
We're going to take input the model there the arguments will be the prompt.

03:23.470 --> 03:25.990
And then in this case we wanted to change the image size.

03:25.990 --> 03:28.670
We're going to do a portrait image.

03:28.870 --> 03:30.550
We get the result.

03:31.110 --> 03:38.970
And then when I get the URL, get that image, and then we'll display the image and return the URL.

03:39.010 --> 03:42.730
So now if we want to use that we would just say generate image.

03:42.730 --> 03:48.370
And then we just pass in that prompt and we pass in the model as well.

03:48.370 --> 03:49.770
In this case flux dev.

03:51.170 --> 03:52.650
But actually we could change that.

03:52.650 --> 03:55.250
So maybe just try a different model.

03:56.970 --> 03:59.730
Flux now is another model we can use.

04:06.090 --> 04:06.570
Cool.

04:06.610 --> 04:12.530
Now we have a portrait image and we're using the Chanel model which is a little bit faster but less

04:12.530 --> 04:16.370
detailed than the dev model.

04:16.370 --> 04:17.850
So it just depends on which one you use.

04:17.850 --> 04:22.250
It's also much cheaper, so you can try out all the different models on replicate.

04:22.250 --> 04:27.330
They give you this code, but as you can see it's a relatively simple API request.

04:27.370 --> 04:29.490
So it really makes things a lot easier.

04:29.490 --> 04:30.730
I prefer to do this.

04:30.730 --> 04:36.610
I used to run stable diffusion on my local computer, and there's stuff that always seems to go wrong

04:36.970 --> 04:38.370
in the setup with that.

04:38.370 --> 04:42.210
And yeah, I've switched everything over just to this because it's much, much simpler.
