Creating Images with Flask and OpenAI Integration
Learn how to develop image-generating applications using Flask and OpenAI, exploring prompts, templates, and more in a comprehensive guide.
File
Audio Transcript Translation with OpenAI Whisper whisper ai learninglogic
Added on 01/29/2025
Speakers
add Add new speaker

Speaker 1: Hi everyone, how are you? I hope you are doing very well. Today we are going to do another project, i.e. our third and fourth project is related to OpenAI. We have taken the audio, we have done the text and only the image is left, so today we are going to do another project related to the image. We are going to run it in Flask and show it to you. You will also write a prompt and on the basis of this prompt, you can generate your image etc. It is a very simple method and we will do it in a very easy way because we did the last project, so almost similar things are going to remain. So let's move ahead and try to apply the rest of the things So I hope you are able to see the screen here You must have seen what project we are going to do today Now you have to see all these things Suppose I have put a value here Create an image So what did it do for us Created an image Now how many images to create here You have all the options Let me just write here Based on this, it will create an image and give you will give you this kind of applications you are going to make today in the next 10 to 15 minutes it is very simple and you will not take much time here, okay, so let's refresh it while it is creating I think it is closed now, so yes, it is closed, so now it is not working, so just let's go here, we change the number to 5, how much we should create it now, 5, so here we will go, we will run it, as soon as we run it and go here and if we refresh it like this and as soon as we put it here create create a image of doggy okay now i don't want a cat now i want a dog okay it will take a little time to create an image of both of them because we have set it to 5 so it will take a little more time in the past, no problem, let's see what is happening, this is amazing, which dog is this, find out its name, it is not so good that we are doing it in a very normal way, but it can be done, you can do things like this, you can do it 5 times at a time, so it is a little bad quality, so if we have to do this, we have to make images like this, we will use a good model and if we set the parameters properly then we can improve the quality of the doc so what we will do here, we will show you all those things for that we have to go here and let me explain you a little bit about the architecture wise what will be the high level design of this so basically we are not doing anything ok, we are not doing anything what is it? normally you use OpenAI's API ok you will use OpenAI's API and you will hit the head by giving a prompt that I want an image so it will hit the model and will ask to make an image now it will make an image and give it to us this is our simple way now what we are doing is we are using flask and converted it into an application form in the last part you have seen how to make a road and how to do things using flask I think you have already seen everything so there is nothing like that so let's start from the beginning and I will explain you in a very easy way If you go to the template, you will see an index.html file Now you don't have to read this file, you don't have to learn it Wherever you work, your index team will make it for you So, you don't have to worry about this If you want to make it, you can go to bootstrap website You can make it according to your requirement So, we don't need to know this code, we are using it as a template So that our project can be shown to you And if you don't want to use it in this way Then you can use another one You can use Steamlit Where you don't have to write this code, this index and all these things You don't have to write everything, you can use whatever you want Okay, we understood this much, let's go Now what we are going to do, this is basic Let's write this file in template, that's why we have put it here The main code we have is very small Now what will we do with this code Let's remove this code here so that I can explain everything to you Now there is one more thing here that you will do So see what you have to do here, I have closed this code here for now And I will clear this So whenever you go to make this project, the first step you have to do here is to create a new virtual environment and activate it. So let's suppose if we remove it and open the terminal again, then it is open. Now we will go here and open the terminal, so how do we activate it? Let's suppose when you have made it, then your environment will be visible here like this. But if you want to activate it, you have to write the name of your environment How to create? Let's know this first So we have to write like conda create-n You can use whatever you want to use After this, you will write the name of your environment Like you wrote myenv or evn whatever you want to write After this, you will put the version of python Which version are you going to use So let's suppose we put python-10 and buy it, so that you don't get asked whether you want to make it or not so if you use it, you will have a new environment you have to work in that environment, why? for this project, you have to download and install some things, so for that you have to install some things so that it doesn't create any conflict in your base environment and whenever you run something again version issues due to conflict different environment you must have downloaded different things if you don't have that problem, then do it in this environment and you won't have any problem there will be no conflict ok now what to do for this now it's done, now how to activate it suppose you made it like this now if you do like this, it will be done at last you will get an option to activate it So, to activate it, what you have to do is, conda-activate whatever your environment name is like our environment name is gen-ai project, because we are going to show you a lot of projects here, so as we do this you can see, now the base was written here now it is activated, so our gen-ai is written here, so your environment is now activated Now, what you have to do is make a requirement.txt file requirements requirements.txt So, first of all, you have to create a file and then you have to install these three things which is the dependency of it. OpenAI version 0.28, python.env and flask, you have to install these three things.

Speaker 2: and after that we have to run it like pip install pip install-r requirements.txt

Speaker 1: as you do this, all your requirements are installed and after this, you go and click here so that your screen is correct ok, so we have done both the basic things we have made our environment we have installed requirement.txt now our main task is app.py file where we will make our application we will write code in it and in .env file we have our api key which we can't open yet ok, and after that if you want to see here index.html this is our html code which is not necessary for us to tell you you just take it and use it Now, let's go to app.py and see what code is there, what simple code is there, let's try to run it here. So, in the last class, I had already told you all these things, so we are not going to go into too much detail. Let's come here and here I did OpenAI, why? Because we have to use DALY and OS, so that we can use our getOS.getenv to load the API key. and to load it, we will use .env we will use flask so that we can make the application we have to request GET or POST for that we will use this and we have to jsonify its answer means as soon as we get the return, the answer will be jsonified and render template so that we can use its template we have to use this template for that we have to use it now our work is to load the API our API is loaded Now to use it, we do one thing, as we went here and put it here Okay, we loaded three things, put it in a variable and through it we are ready to use it with the name OpenAI Now our main task here is to create an app for our application We started creating an app from here, now we named it Flash Why we do it, I have already explained to you in the last class Now what is our main task here now the simple things we have if you see you will see that we have created a function named defecindex whose function is to keep index.html file here keep this file here whose function is to read this that's it you will say ok now what we have to do here it will render I want to use OpenAI here, so what I have to do for that I will make a route and what will be the work of that route Look at this, I made this route and what I have to do in it Generate Image, as you can see here If you look here, you will get this message And here we have written all these things there In the index.py file, now we have written this We have given space to put a prompt here, that's it, we have made a route Now we have to pass a prompt in it, so we will put a small We will put a function here. Let's see what the function is. Generate and pass your prompt in it. Print the prompt, whatever comes to us, our prompt will be visible. Like this, whatever the prompt will be, we have put it here to print it. Let's go. Now here you will see, you have to give a response. So we just used OpenAI image create and put a prompt in it. Whatever we pass here, it will come here directly. And how many images to make, let's say we want to do one about this. So we put one here. And what will be the size of its image? we put it and printed it whatever the answer will be, it came and returned this thing in json format because the answers of ipi comes in json is it done now? that's it, that's it it's very easy, I hope you found it easy and after that we have to run it, what will be the host? it will be our import and this project is ready for us now there will be no problem, now we have to run what will you do? you will go here and this app.py file when you run it, it is ready after it is ready, go here and refresh it to see if it is ready now write here create

Speaker 2: a image of a indian girl

Speaker 1: make an image of an indian girl let's see if it is working or not see it is very simple this is creating our image this is not looking like indian at all this is not looking like indian at all we have not set more parameters if you add parameters then you can just make it better you can make your image better with let's suppose sorry now let's submit here how to make it let's see this project is good but you can use it you can use it and show make something different make cat and boy that was better so I hope you like this project because we have not focused on parameters and you can easily explore what are the parameters and which things you want to use and you can change accordingly so that's it so for today our project is done Let's move ahead and take you to the main screen So I hope you understood everything Today our OpenAI has been completed Now we are going to see in the next classes What is our database? Because we have covered everything else We will talk about vector database What is it? How do we use it? Which vector databases are available? What are the actual uses of those vector databases? We are going to see everything in the next classes So thank you for watching the video See you in the next video, till then take care and bye bye Okay, let's go

ai AI Insights
Summary

Generate a brief summary highlighting the main points of the transcript.

Generate
Title

Generate a concise and relevant title for the transcript based on the main themes and content discussed.

Generate
Keywords

Identify and highlight the key words or phrases most relevant to the content of the transcript.

Generate
Enter your query
Sentiments

Analyze the emotional tone of the transcript to determine whether the sentiment is positive, negative, or neutral.

Generate
Quizzes

Create interactive quizzes based on the content of the transcript to test comprehension or engage users.

Generate
{{ secondsToHumanTime(time) }}
Back
Forward
{{ Math.round(speed * 100) / 100 }}x
{{ secondsToHumanTime(duration) }}
close
New speaker
Add speaker
close
Edit speaker
Save changes
close
Share Transcript