---
title: "Improve Media #1"
video_id: 7wh8iFJiShQ
url: https://www.youtube.com/watch?v=7wh8iFJiShQ
workflow_page: https://workflows-of-ai.com/workflow/improve-media-1
language: en
captions: generated
---

0:01 hey there Marcus here uh today's
0:03 workflow is very specific for people who
0:05 works for Drupal uh specifically working
0:08 with the media module so my idea is that
0:10 we're going to take the document type so
0:15 PDF word and so on and supplement or
0:19 basically Elevate the the metadata that
0:23 exists for it so usually when you
0:25 install it usually you just you know you
0:27 have a
0:28 title uh that you usually becomes the
0:31 the file name of the file you upload or
0:34 if you manually fill it out then and and
0:37 that's it and then you can of course add
0:38 fields on top of this add it manually
0:42 takes a long time so my idea here is to
0:45 basically automate the process
0:49 um so what I thought I would add is uh a
0:54 longer summary the whole text so the
0:58 whole text from the PDF so it become
1:00 searchable right because then you can
1:02 have it in solar you can search for
1:04 whatever is inside a PDF a shorter
1:07 summary because maybe you need to uh
1:09 preview it like one two sentences
1:12 somewhere
1:14 uh added search
1:16 words uh so it's you know you can add
1:19 another field in solar and make those
1:21 specific search word more important
1:25 because AI open AI is pretty good at
1:27 figuring out what something
1:30 actually uh what what a document
1:33 actually is talking about so so like the
1:37 context of it right uh I will also
1:41 create a preview image because a PDF
1:44 usually comes you know with
1:47 uh like a PDF icon and there's no
1:50 preview image so I will be a little bit
1:52 creative and actually create an image
1:54 for it as well so we can preview it
1:56 nicely as well with done actual image um
2:01 so to do this well first I can show you
2:04 I will just use some thing I found
2:06 online which is some iPhone 14 pro PDF
2:12 document uh with sales
2:14 argument um
2:18 and I will be using ddev so I installed
2:21 it you can go to
2:23 d.org u i mean you can use toxol you can
2:26 use Lando whatever you want there but in
2:29 this case I wish show you how to do it
2:30 with d we're going to use two of the
2:33 inator so we're going to use AI inator
2:35 convert API which is a simple module
2:39 that basically makes sure that we can
2:41 take a PDF and generate text from that
2:45 uh there are other solutions for these
2:47 but these are not native to PHP you
2:50 usually have to install some application
2:52 on your servers which you might not have
2:55 access to actually do if you're on
2:57 manage hosting so we're going to use the
3:00 convert API and then we're going to use
3:02 open a AI to basically uh fill out all
3:06 these fields then so let's uh get
3:10 started on our site
3:13 so I can show you here I've just
3:17 generate the site basically we're going
3:19 to log
3:21 in uh first thing we're going to do is
3:25 do
3:26 DD well I'm going to copy it here so
3:29 what I need to do is basically copy this
3:32 composer Command right so I'm going to
3:33 get the convert
3:36 API and then I'm just going to copy the
3:39 open AP open AI here as
3:42 well so ddev and ddev is a prefix
3:46 because I'm using ddev so it depends on
3:48 what uh local environment you're using
3:51 basically then we go to extends we're
3:54 just going to enable this then um oh I
3:58 will uh
4:00 I have already got an admin toolbar I
4:02 always use admin toolbar you should do
4:03 as well uh so we take convert API and
4:07 open AI here and then we're going to
4:09 enable media as well because I don't
4:11 think that's enabled by default yeah
4:15 media and
4:18 install and this will install open AI
4:20 Core and some some other modules that uh
4:24 are dependent on them then so first
4:27 thing it does is complaining I don't
4:28 have open
4:30 uh AI key so I'm just going to add it
4:33 here so uh let's log in
4:38 here we log into
4:42 API oh I was already logged in it looks
4:46 like so I'm just going to get the API
4:48 Keys create one and just so you know
4:51 this API key is here you can try to copy
4:53 and use it I'm going to remove it after
4:55 you you looked at
4:57 this conversion and we just call
5:02 that copy it and we just put it in here
5:07 API ke save then it's the same then for
5:12 our uh web services convert API config
5:17 so same thing here login I'm already
5:20 logged in and then it's under
5:22 authentication API secrets we just copy
5:25 this and I think this is two Val no it's
5:28 just one okay
5:30 so
5:33 um oh we can close those now close all
5:38 these windows basically so now we have
5:41 set up that so we actually have a media
5:43 here now so there is a document already
5:45 that has the uh uh where you can upload
5:49 documents right and this takes PDF so we
5:52 can just start by trying this out we're
5:54 just going to add a media here that's a
5:56 document I'm going to upload this um
6:00 file that we had there save it and
6:03 you're going to see now you know it uh
6:07 it did upload but it's doesn't look that
6:12 I mean you don't have that much
6:14 information you have the information
6:15 that the file name is this and you have
6:19 the file so now we need to add some
6:22 fields to this so we go to Media types
6:24 and document manage
6:27 Fields I will start with a form the TT
6:30 long that is long
6:37 description and I will set that to full
6:40 HTML enable AA interpolator so that's
6:43 the thing that's going to uh take some
6:46 text oh now I went one step
6:50 uh I have to do the conversion from PDF
6:53 to text first so I made a mistake here
6:55 I'm just going to save this not enable
6:57 yet because the first thing we're going
6:59 to to do is that we're going to create a
7:01 plain text text plain long that is the
7:05 original text there is one thing you
7:08 should know PDF is
7:11 horrible as a structured format so doing
7:16 the conversion from PDF to uh text can
7:20 uh give you very bad uh results
7:23 because it's it's not very clear how
7:26 everything tracks horizontal to vertical
7:29 and so on might be that it reads this
7:31 first and then this because it thinks
7:34 this is a row and then it reads 100%
7:36 100% 100% right uh it depends a little b
7:41 a little bit about how it was set up so
7:45 it's actually a quite horrible uh format
7:48 just so you know so the results might
7:49 not be super but let's
7:52 see so I'm going to enable Ai
7:54 interpolator and I'm going to enable uh
7:57 text from document
8:00 and we're going to use the document as
8:02 the uh field where we're getting the
8:04 text from and we make sure that the
8:06 weight is 100 I'm going to turn on batch
8:09 mode because we're going to add a lot of
8:10 layers now so we don't want to have a
8:13 timeout so if we were to do direct it
8:16 tries to store everything in one uh
8:18 server request which is not optimal so
8:22 we save
8:23 this now then I can go to Long
8:26 description enable a anator and use open
8:30 AI text long and we use the original
8:33 text as the base and based on
8:37 the context
8:40 text
8:42 create uh one
8:45 paragraph no create oh sorry create 16
8:50 sentences of summary of
8:54 it context and the context then is just
8:58 the text that we just got from the
9:02 PDF
9:04 so I'm just going to write copy this
9:08 here which is the context which is then
9:10 the text is going to be replaced when
9:12 this is run we take inter Play We 101
9:16 because this has to happen after uh we
9:20 got the text from convert API right uh
9:23 I'm going to take gp2 T4 turbo because
9:27 it might have a too long context uh
9:30 otherwise batch because the amount of
9:33 words here might be over 16,000 which is
9:36 what GPT 3.5 handles otherwise GPT 3.5
9:40 is actually quite okay at
9:42 summaries uh it's very bad at other
9:44 stuff but summaries is very okay yet so
9:48 we're going to save this and then I'm
9:50 going to create another one that is then
9:53 the short
9:58 description by the way Drupal just
10:00 changed how everything works here so I'm
10:02 still a little bit not accustomed to it
10:05 yet um short description it's better but
10:09 yeah uh full HTML enable AI interpolator
10:13 open AI takes long we base it on the
10:16 original text we could in we base it on
10:19 the long description as well uh actually
10:22 let's do that just to save some money
10:24 because the long description is still a
10:26 lot shorter than the PDF right
10:30 based on the context write a two
10:34 sentence
10:35 summary
10:37 of
10:40 uh of the context I guess that's
10:47 okay I mean this is prompt engineering
10:51 you can get better results when you try
10:54 try around and try to get the correct
10:56 pront basically so in this case I now
10:59 have to set this to 102 then because the
11:01 long summary has to exist before the
11:03 short summary and in this case we can
11:06 just try GPT 3.5 turo because it's going
11:08 to fit in the context
11:10 bace uh next thing we wanted to add was
11:13 search word so I'm going to use plain
11:15 text in this case and I'm going to do
11:18 short so I'm just going to split it up
11:20 in multiple words that you can uh
11:22 control
11:24 basically um search words and then I say
11:29 unlimited here because you you you can
11:31 add as many as you want I'm going to use
11:34 open AI string I'm going to base this on
11:36 Long description as well based on the
11:40 context text
11:42 suggest uh let's say 10
11:46 to 15 search words that are unique and
11:52 important when
11:55 searching for this
11:57 document
12:00 and then we add context
12:05 here
12:07 so same thing here this has to be 1002
12:10 at least right
12:12 because the description has to uh exist
12:16 before in this case I will use GPT 4
12:19 because it's it's going to create better
12:21 words basically it's going to know how
12:23 to create better
12:24 words save this
12:27 um
12:31 the last thing we want to do now well
12:34 it's two-step thing so we want to take
12:36 the plane text we can take text plane
12:39 long and do uh header image no sorry
12:43 header image prompt is what I want so
12:46 this is going to create a prompt that
12:47 we're going to use to generate the image
12:49 right we enable a interpolator once
12:52 again open AI string long once again
12:54 long description once again based on on
12:59 the
13:00 context um
13:04 gener generate a one sentence image
13:10 prompt uh of an
13:14 artistic kind for
13:17 a uh preview
13:21 image of the
13:24 text be
13:27 abstract and and uh have a
13:33 futuristic uh futuristic style let's do
13:36 this this time
13:39 context once again we fill it out with a
13:43 context so the long description is
13:45 basically doing all the work in this
13:47 case so if if that is not uh very well
13:51 written the rest will actually kind of
13:54 fail in this case and we do batch we do
13:57 GPT 4 turbo where are you there save
14:02 this last thing we want to do then is we
14:05 want to do a image field that is there
14:08 preview
14:11 image um I just enable everything here
14:16 and disable uh open a dolly we're going
14:20 to use the header image
14:23 promp and we just take it as it is since
14:26 the prompt to generate the image and
14:28 this way have to set to 103 because this
14:30 has to exist even later so this is the
14:33 last thing we're going to
14:34 do uh yeah I'm just this yeah okay let's
14:40 do horizontal we do neutral let's do HD
14:43 standard see if we can get something
14:45 nicer might take a little bit longer but
14:47 that's
14:48 fine uh and that's it basically we can
14:52 keep everything in manage form display
14:53 in manage display I don't want the
14:55 header image promt to show up uh or
14:59 actually I'm not sure if anything there
15:00 should drop but we can wait let's just
15:04 keep it there so we can actually see the
15:05 result because how you style this as I
15:08 said in the beginning this is for people
15:10 that already know stuple so you know how
15:12 to style this uh show which Fields you
15:15 want and so on so we're just going to
15:18 Well I will do one funny thing here I
15:21 will just edit this view so we're not
15:23 going to take the built-in thumbnail but
15:25 the preview
15:27 image and and let's do thumbnail here
15:32 link image to
15:33 [Music]
15:34 content and we just rearrange this put
15:39 this instead of the thumbnail apply save
15:42 so now there's no previe image but
15:44 hopefully after we resave now it's going
15:47 to fill out all these fields so you see
15:49 oh this didn't look too nice though
15:52 maybe we should pull it up a little bit
15:54 I wonder where the fields were even uh
15:58 uh let's just pull
16:00 up everything here to
16:03 the
16:06 top hopefully that looks
16:10 better so you can see what I'm talking
16:13 about here let's see there we go so you
16:17 have the
16:18 document uh this is well let's just
16:21 order them in the order that it's
16:23 happening because I created them in the
16:25 wrong order so this is then going to uh
16:30 because it recognizes it exists a file
16:33 and it recognizes that original text is
16:35 empty it's going to ask convert API now
16:38 hey please I need a text it's going to
16:40 fill out this then the next step is that
16:42 the long description is going to
16:44 basically ask open AI hey create a a
16:47 long description from the original text
16:49 short description ask open a hey create
16:51 a short description from long
16:53 description search words hey create
16:55 search words from the long description
16:57 other image hey create create the header
16:59 image prompt from the long description
17:00 and then the oh it should be preview
17:03 image prompt I'm not consistent here
17:05 anyway preview image gets generated and
17:08 so if I click save now it's going to
17:09 start and this will probably take some
17:13 time now so I should probably have
17:15 explained that while I was waiting for
17:18 this because I have no nothing
17:20 interesting to say now so let's see
17:26 um because the first step is pretty fast
17:30 so converting the second is probably
17:32 going to take some time because the
17:33 document as you can see it is pretty
17:36 pretty large um
17:39 so it will take some time so one thing
17:42 that's interesting maybe if you if
17:44 you're running like e-commerce is what
17:47 you could do in this case is that if you
17:49 have something like this
17:52 already uh for all your products but you
17:54 don't have very good uh selling text you
17:57 could generate a text field and
17:59 basically ask it based on the manual or
18:02 something just generate uh uh selling
18:06 text
18:08 and uh one more example for commerci
18:12 while we're waiting okay now it's
18:13 finished but anyway I would just mention
18:15 it in the open AI module there is the
18:17 FAQ field so there is FAQ for druple
18:20 right so if you want to have a
18:23 frequently Asked
18:25 question about your uh
18:29 each product in your Commerce you could
18:31 use this method as well it takes a PDF
18:33 and just generates uh frequently asked
18:36 questions based on the manual of a
18:38 product right so maybe there's a
18:40 troubleshooting section it can just get
18:42 that then anyway you see now there's a
18:44 preview image uh it started first of all
18:48 here we have the full text you can see
18:51 that the structure is not super it's
18:53 because it's PDF if we were to use word
18:55 it would work better but I wanted to
18:58 show actually the worst case scenario so
19:00 you can uh see what you can
19:04 expect okay this failed spectacularly
19:08 actually uh let's rerun it then I don't
19:12 know what happened as I said when the
19:14 long descriptions fail everything fails
19:16 so we just going to remove all
19:19 these because then it runs again
19:24 right so so and we save again in because
19:28 then it reruns
19:30 again so the the initial prompt of
19:34 creating the long description there is
19:36 one thing that's very important to think
19:38 about when you're prompting here and I
19:40 will see if it fails again I have to
19:41 reprompt
19:43 basically that the AI interpolator or
19:47 the open a open AI version and most of
19:50 the plugins are made to also be able to
19:53 create multiple Fields because this is
19:54 important if you do uh use the serf
19:57 plug-in for in inance you want all the
19:59 different websites that it finds you
20:01 don't want just one right or if you want
20:03 to create a gallery of images you don't
20:06 want to create 10 fields for that you
20:08 just want to create one field with
20:09 multiple
20:11 files of course this is true as well
20:13 when you generate text so you have to be
20:15 very clear where you say how if it
20:19 should be split up or or or not so if
20:21 you for instance mentions create 10
20:23 paragraphs it might try to create 10
20:27 different text
20:28 areas right and this will of course not
20:32 work if you only set one because it will
20:34 only save the first
20:36 one okay so this still
20:41 fails so let's retry
20:46 this oh wait wait I have to rewrite
20:49 first the prompt before we go anywhere
20:52 else so I want to be honest with how I'm
20:54 using the uh the anator this is not a
20:58 sales pitch you you're you know I'm not
21:02 it's it's free I'm not earning any money
21:05 on this right I I I just use it myself a
21:08 lot so would be happy if you also use it
21:12 so because of this all the videos I do
21:14 they're not pre-planned so stuff can
21:16 break and and I guess it's useful that
21:19 you see that sometimes it breaks and I
21:21 would show you maybe how I can fix
21:25 it so based on the Contex create 16
21:30 sent well let's write like this create a
21:33 summary of uh up to 16
21:40 sentences in one paragraph so we're
21:43 going to be very specific that this one
21:45 paragraph now let's see what
21:52 happens just remove all
21:55 these remove this and run again
22:00 let's see if it works better so by the
22:03 way also now you see there's one less uh
22:06 process that's running so from the
22:08 beginning I think it was six and you're
22:09 going to see when it's finished with the
22:11 first one that it did one out of five
22:14 because the conversion worked right so
22:16 that we don't have to run again I never
22:18 emptied that field so but if I would
22:21 want to then run it again I could empty
22:24 it of
22:26 course
22:28 so let's see if my changes now did any
22:33 difference to the
22:44 output yay okay it's still not
22:48 very very
22:51 good this is interesting why is the
22:54 summary short I probably did some error
22:58 there so it's full HTML open AI long
23:01 description based on the context create
23:04 write a two sentence summary of the
23:06 context oh you see what I did there I
23:08 should copy and paste so we save this
23:13 and then I'm just going to remove this
23:15 so we run that again but here you see
23:17 now it actually
23:19 worked uh I'm just going to Res sa
23:23 this so if you do this based on my video
23:26 you know what not to do at least now
23:29 um so now we have a little bit longer
23:32 couple of sentences here we have two
23:34 sentence version Oh this is another
23:37 thing so another thing went wrong here
23:39 actually uh GPT
23:42 35 so basically we're running Json in
23:44 the background right uh because we need
23:47 a structure format to do this and J chat
23:50 GPT uh sorry GPT 3.5 is not
23:54 always understanding in how to do this
23:57 I'm still sitting experimenting to try
23:59 to get this perfect that's one of the
24:01 reasons I haven't done this production
24:04 ready yet so if this ever happens that
24:06 it shows you chase like this happened
24:08 again let's try again then you can just
24:11 remove it and resave it and in worst
24:13 case if it happens too much you can just
24:17 okay this was even worse you can just
24:19 run uh gp4
24:22 basically and here you see by the way
24:24 it's just rerunning this one okay so I'm
24:28 just going to change this to uh GPT 4
24:33 because GPT 3.5 seems to have problems
24:36 with this
24:37 currently so GPT
24:41 4 see if that works
24:46 better so
24:48 yeah as I'm said I I mean I could rerun
24:51 this recording now make it perfect but I
24:53 want to show you how it actually is to
24:55 use it because it's not always perfect
24:58 it's always better if you have the money
25:00 to G use gp4 but I understand that
25:02 people want to save money and it's a lot
25:05 cheaper to use
25:07 3.5 so I I am trying to perfect this
25:11 prompt that runs in the background and
25:13 if someone wants to help you know the
25:15 code is open source you can just
25:16 download it and check what I'm trying to
25:18 do in the background with these prompts
25:20 because it's not just running the
25:22 prompts you see uh that you put into the
25:25 U it's running a lot of stuff around
25:28 that to get it uh in a structured format
25:31 so it fits fits complex Fields basically
25:35 so
25:37 anyway now we have the document we can
25:40 put this into the search right so if you
25:43 use leic search Soler search API
25:45 whatever same with these search
25:48 words uh is also stuff that's basically
25:53 important for this specific uh document
25:57 based on what GPT for things then of
26:00 course uh we have a short description
26:03 that we could use for a preview we have
26:04 a preview image here wait let me click
26:07 on it full screen it
26:11 so yeah maybe maybe I need to prompt
26:15 that a little bit better I'm not sure if
26:17 that's a preview image you want to show
26:19 um but it's just to show you the idea
26:22 and here you have the header image
26:23 prompt by the way then um so so yeah
26:28 that's it this took a lot longer than I
26:31 thought but it's as I said it's good to
26:33 that I show that sometimes stuff doesn't
26:36 work first try uh first time you try it
26:40 and then it's you can see what you can
26:42 change
26:43 because this is also one thing that's
26:46 very important to note compared to any
26:48 other development I have ever done uh I
26:51 worked on super big projects and so on
26:54 everything else is deterministic where I
26:56 can say basically
26:58 based on some project managers or
27:00 product owners initial idea is this
27:03 possible yes this is possible you know
27:04 this is not possible yes I have to
27:06 research or
27:09 whatever AI in that sense or GPT large
27:13 language mod models they are not
27:15 deterministic if you ask for one thing
27:17 it might answer something else depending
27:20 on on how you ask matters as well right
27:23 so that's why prompting is really really
27:25 important and basically doing trial and
27:28 error on this so yeah so
27:33 I yeah I hope you find this interesting
27:36 uh you know now how
27:38 to basically get the media model uh
27:41 sorry the media entity to get a lot of
27:44 metadata to it so thank you for
27:47 watching
