Build AI Marketing Tool and Image Generation App with PHP and OpenAI GPT-3 for Beginners

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
hello everyone in this video I'm going to teach you how to use open AI with PHP we are going to learn from creating a simple project that can generate three Facebook captions for marketing for us alright for example this is our application the UI is not look good but it works for example I'm going to generate three Facebook captions for shoe over here I click on generate and then I will get the output like this you will see step into new season with our collection of stylish shoe shop now and get 10 of your first purchase and is give you hashtag shoe store this is the second captions that is provided to you and this is the third one what if I want to generate for like something like a burger I click on generate I will get three captions for Facebook all right it's really cool application and you can even generate image over here for example I want to generate Burger image I click on generate all right let's talk about the development tools that we are going to use to develop these projects the first one you need to install Sam to set up PHP environment development you have to make sure you can download them over here go to Sam go to here and click download if you use window and install it on your computer the installation is pretty simple you just click next next until it's done all right the next software that you are going to use is composer we use composer to install PHP Library okay make sure that you uninstall composer on your computer as well go to download over here and then you can download exe files over here and click on the files when it's done download and just click next next next until it's done the third software that you need is Visual Studio code this one we use for text editor or code editor okay you can download this from this URL and open AI you really need open AI as well you go to this website go to API you sign up create an account I have created an account so if you can create an account you will get free trials for like 300 or something I don't know the policy might change but you will get free trial because I've used all three trials so I have to pay for this application and you can go to personal over here and then you can go to view key you can create new secret key over here you just copy this key and use it with your application this is all the setting uh you can see how much that you use this API over here you can keep track of your using AI API over here this is all okay when you install Sam you can go to Sam control panel over here and you have to start Apache server I'm going to stop it because I have started it okay I started again start it again make sure this one start because you want to access to localhost okay The Next Step let's go to drive C okay and then go to Sam folder over here and go to hdocs okay let's create a new folder over here I'm going to name it uh PHP AI app okay uh it can be uh uppercase or lowercase it doesn't matter okay let's open this folder with Visual Studio code you just drag and drop this folder into Visual Studio code icon over here and this window will pop up and then let's create the first PHP files over here list name is index.php okay I'm going to create HTML structure over here and let me create a first PHP tag over here let's print it out Echo hello PHP okay save it and then you open your web browser and if you go to localhost and name of this folder phpai app okay PHP AI app hit enter you will see Hello PHP over here which is this code I want you to go to terminal new terminal let's check if you have installed composer successfully type composer dash dash version and hit enter it will show composer version over here if you've installed composer on your computer alright the next step we are going to install SDK PHP library for openai okay let's go to open AI okay you go to AI and you go to docs over here all right it will tell you over here how to use this quick start you might go to library and if you scroll down you will see PHP over here so they recommend you use this Library okay I'm going to click over here this will redirect to packages over here you can click here to see GitHub okay this is how you install this document you can read it if you don't want to read it I'm going to teach you how to use it all right let's copy this one to install the package into our project paste this is over here okay hit enter okay after is have installed you will see composer folder over here and you will see the name of the package that we've just installed and the next step we are going to create a form okay for PHP application let me create a form over here this is uh the form that we can input information for example over here let me create div and then I'm going to type H1 over here over here I will write writing three Facebook marketing caption okay four and over here let me create new div okay let's create form over here and then let's create div over here and over here I'm going to put input type text and then name name is uh prompt you can name it whatever you want but when you access to this input you have to use the same name okay and then over here placeholder I'm going to like four shoe Burger exaggerate okay and over here let's create new div and then let's input type submit okay and value I put is generate okay and let's take a look at our application okay let's go to localhost and then PHP AI app and enter you will get something like this uh let me put brake line okay and then let me go back here and refresh leave it I can refresh this face okay okay this is our UI so we have UI right now so we are going to create a new files over here and name it ai.php okay when we submit this form when we click on this button okay I want to use action we will send this information to these files okay then we put uh the file's name ai.php and method that we use to submit information is post so we just post over here when we access to the information we have to use post okay let me create PHP tag over here and then let me Echo post okay prompt okay save and if I go back here and if I refresh if I enter something over here like shoe and generate I will get shoe over here which is the code over here okay let's remove this one go back to this documentation so this is how you can use this the first one you need to include Auto load into PHP files so you can use this Library you can copy the code you can type it okay let's let's type it together require Dr okay dot and then we go to photo vendor Auto load so we can load a package.json oh over here then we are going to use this Library use uh Ohana day and open AI let me copy I'm so lazy let me copy this one okay we copy it and put this over here okay the next step we have two to copy this one so I will explain You Lie by lie okay this one is to load the key from our application so you where you can get the key I have talked about this before you go to open Ai and then go to personal and then go to view API key okay I will remove this key and let me create no key I will copy it you can use the same key with me because I will delete it after I finish these projects make sure that you use your own key so I will put the key directly over here because I don't want to waste time setting up environment variable okay and the next step over here we can create new openai objects by using this key okay okay let's type it out together okay all right we create open AI variable open AI equal to no no this object okay we call this object and then we pass the key to the object okay okay the next step we are going to create a prompt variable okay we receive data from post and prompt okay The Next Step I'm lazy to type again I'm going to copy this one and put this over here okay this model is our update we are going to use no model let's go to overview uh let's go to documentation of open Ai and then go to model over here so the model we are going to use is GPT 3 which is this model this is the latest model you can copy it and then you just paste it over here all right this is the model that we are going to use for the prompt uh we are going to create a prompt over here so the problem is what you want your AI to do so I want is to write three marketing Facebook caption for for what for this prompt okay I just connect it with this variable okay and this one I change to Capital later Facebook uh temperature you can set it if you increase the value it will be more random okay token how long the text output you want to generate over here I want is to generate only 150 and this is frequency penalty is about a word repetition so if you increase this it will increase word repetition okay and this one is presence penalty is about topic repetition okay you can increase it lower it adjust its fine tune it by yourself and if we follow the documentation over here we will we can bottom the complete output over here all right okay let's try the application again the first go to this URL and then type shoe hit generate okay this is the output okay this is the output that we get Choice here this is the output it's choose only 69 tokens I'm going to extract our output form complete so we have to convert this to Json okay let me declare variable respawn and then let me call Json decode function and then let me pass compete over here okay this complete passage here and set this one to true and then I will get respawn tags from here and then respond and we access to choice this one right and then array 0 twist this array array 0 and text array 0 and and text okay let me create HTML structure over here okay let me put output over here and over here I can put div and show PHP over here print out PHP okay I can use this to respawn over here save and if I go back here I generate it again you will see I will get output like this I'm going to use CSS to Styles this tag to break a new line here I want this to break a new line so what I can do I can go here and I put styles put class over here I put output text okay let me call class over here I'll put over here I will put white space break space okay over here I will put H1 output of three Facebook marketing captions for over here we can type um for prompt okay show prompt from save it all right if you go back here and let's refresh generate it again okay you will get three Facebook caption over here all right this works so good the next thing we are going to generate image instead of text okay to generate image I can put HR over here so let me copy this one and put this over here and over here I will change this to inmate generation by AI okay and over here I will copy these files and paste it over here I change this one to image Dash AI okay and then over here I when somebody click on this form I want is to send information or prompt to image Dash AI image Dash AI okay and the this one can be prompt as well and this one generate image okay save and if you go back to our application we refresh it you will see image Generation by AI over here so let's take a look at documentation how to generate image together so in order to generate image you have to scroll down to see how you can create image over here create image so you have to use this one you have to call Image instead of completion you call this one image okay and then this one you can copy this parameter okay and replace this over here okay and let me delete this one and let me comment this one and if you bottom this one okay complete what I mean you will see the URL of the image that generated by AI okay let's go back here refresh here again and put like Burger click generate image see you will see URL over here so how you can access to this URL I will show you all right we have to convert this one complete to be Json object okay this is how you can convert it all right let's create HTML tag over here HTML5 okay let me show our printout image let me create div over here and H1 here is your image generated by AI okay let's create a div over here so we get Json objects from respawn over here okay over here I will create image tag image source okay close this tag so the image is in url right we put respawn over here and then it's in data over here so we put data over here and it's in zero array over here so index arrays of zero so we put 0 over here and then it's in url okay put URL over here all right this should be good if we go back here we refresh the page and I want this to generate shoe image click generate image over here what why is generate cat image for me let's try it again let's oh I forget to change this one The Prompt over here okay I will change is for to be like uh prompt over here okay let me refresh this one and let me put shoe again and generate image so it will take this word and send to AI I want to generate shoe image can you generate for me it will generate for you you can't adjust the image size over here as well just put what side do you need from Ai and over here if you want to adjust the prompt you can put like image like shoe image uh over here icon cat with ADD attacks for Facebook marketing okay save it and let's refresh over here Burger let's generate image for Facebook marketing see this is the burger for Facebook marketing so you can adjust the resolution the size of the image over here you can play with the prompt The Prompt is really important for you what kind of prompt that you put into uh this parameter will affect your output directly alright if you like this video feel free to click like subscribe and comment down below thank you so much for watching
Info
Channel: Devtamin
Views: 9,483
Rating: undefined out of 5
Keywords: coding, coding tutorial, programming tutorial, web development, Artificial Intelligence, AI, OpenAI, Code OpenAI, OpenAI tutorial, ChatGPT, GPT-3, OpenAI PHP, PHP OpenAI, PHP GPT-3, GPT-3 PHP, create app with OpenAI, web development and AI, orhanerday, php orhanerday, OpenAI orhanerday, create AI app with PHP and OpenAI, OpenAI GPT-3 Api Client in PHP, code PHP with OpenAI, develope website with PHP and OpenAI, php tutorial, php programming, PHP and AI, AI for Begginers
Id: RUGzQ9Dv9fc
Channel Id: undefined
Length: 21min 27sec (1287 seconds)
Published: Thu Feb 02 2023
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.