So guys, yet another amazing project with the help of Google Gemini Pro.
And this time I am probably creating an app which is basically called as Calorie Advisor.
And with the help of this specific app, all you have to do is that whatever food you specifically eat
in a day, right?
Let's say breakfast, lunch or dinner, you just need to click a photo and probably give to this specific
app and this app, this LM app or sorry Lim app, large image model app will provide you a response
with respect to how much calories you are specifically eating, whether the food is healthy or not,
and what all contents are specifically there in the food.
Uh, the reason why I'm making this particular video, uh, this is for your own health, because,
uh, just a couple of months back, my health was not that good.
The reason was that the main reason was about food itself.
Right?
So we really need to have a good food, which has a lot of nutrients, which has proportionally everything
like carbohydrates, fats, you know, fibres, lot of fibres, protein.
Right?
It is it is said somewhere in one of the research paper that for every, every kilogram of our weight,
you know, every, every, every, every kilogram of our weight, we need to probably consume somewhere
around 0.8g of proteins.
Right.
So considering this, you know, uh, an average like a 75 kilogram person, right.
Uh, may need to have somewhere around 15 50g of protein.
So this app will probably help you to at least find out whether you're, uh, you're eating a good food
or not, whether, uh, proportionally, you are getting all the nutrients specifically that you really
want.
Okay.
And again, uh, I will try to implement this specific app completely from scratch.
Uh, it'll be super beneficial because it is now probably for your health itself.
So I would suggest you all implement this.
Um, and at the end of the day, I would definitely tell you guys, please follow a strict diet, uh,
even though you're not exercising a lot.
But at least diet should be very much neat and clean as you grow up, right?
So, uh, let me just go ahead and share my screen.
So here I will probably show you the demo.
So here you can probably see I will go ahead and upload some image.
Let's say one of the food image I'm probably uploading.
And this is what is the food image.
It has mutton biryani.
It has chicken.
It has eggs.
It has a lot of items.
Okay.
Now if I go ahead and click on tell me about the uh, total calories.
Right.
So as soon as I probably click this you'll be able to see all the response this entire app is running.
Now from this particular image, uh, the Google Gemini Pro uh, vision API will probably take out all
the details.
Like what?
All things are there in terms of food items.
So here you can see the food items in the image are chicken biryani.
And right now this much content of chicken biryani is somewhere around 600 calories.
Then you have mutton curry 300 calories, egg curry 150 calories, potato fry 200 calories right 100
calories.
Uh, banana 100 calories.
Buttermilk 50 calories.
Now total calories is somewhere around 1500 calories.
Okay, now, uh, if I probably say whether this food is healthy or not.
So here you can see the food is not healthy as it is high in calories and low in nutrients.
It also, uh, it is also high in saturated fat and cholesterol.
The food is not balanced as it does not contain enough fruits and vegetables.
And you can see the proportions.
Right.
So carbohydrate is 60%.
Now when carbohydrate is more right.
Uh, let's say that you're consuming more rice unless you don't do gym right, that entire carbohydrates
will not get converted into energy.
Uh, in short energy.
Yeah.
So over there you'll also be seeing fats 20% fiber is very less, 10% sugar five and others five.
So all this information you can probably see, let me just put another image and show you because this
is the same thing we are going to implement.
Okay.
So here I've downloaded one of the image over here.
And this looks like a very healthy breakfast.
Here you have spinach.
Here you have scrambled eggs and tomatoes right.
I'm really cautious about food nowadays guys.
I'm I'm eating a lot of clean food.
I eat lot of millets, you know, like bajra and all.
So it's all more about my diet.
And soon when you see my transformation, I will try to do it.
Probably in some months.
Then you'll be able to understand.
Okay, so here you'll be able to see the response is scrambled egg 90 calories.
Spinach seven calories.
Tomato 16 calories.
Somewhere 115 calories.
The food is healthy and provides a good balance of carbohydrates, fats, fiber, and sugar.
The percentage split of the ratio of carbohydrates is this.
Uh.
Another thing is as follows.
Carbohydrate is 50% fats 35%, sugar five other five.
Right.
So over here also it shows carbohydrate is 50.
Uh, but I think it should provide a little bit more accuracy.
What I see from this.
Because at the end of the day we are having scrambled eggs and spinach.
Uh, yeah.
Based on this much calories, I think this is correct or not.
Let's see for this.
But other than this, if I probably compare with respect to the total calories and all, and this is
obviously a food is very healthy, right?
So we will go ahead and try to.
Implement this entire app.
It will be fun together when we implement this because I'm going to do completely from scratch.
So let's go ahead and let's start this specific application and let's work towards this.
And let's see that what all things we can basically implement in this.
Right.
And again as usual I will start with my VS code.
Uh, we will do completely from scratch from creating an environment as I've uh, as I usually upload
all my project videos in this specific way.
Right.
So first of all, I will go ahead and probably create a command prompt.
First step is always to create an environment.
So I will go ahead and write conda create minus p v and v with respect to Python.
And again I'm going to use 3.10.
And I'll go give VI 3.10.
Why.
Because Google Gemini makes sure that like it is supportable for at least Python greater than 3.9,
right.
So I'm just using 3.91 uh 3.10 in short.
Right.
So once this packages gets created.
So here you will be able to see the V and V folder is there.
Now along with this I'm also going to create some important things.
Let's see.
Um I will click over here.
So one is the dot env file okay.
The other one is basically requirement dot txt where I will specifically give all my libraries.
So inside this dot env file.
First of all I will go ahead and write my API key.
Right.
And how do you create this Google API key?
I've told many times in my video go to Maker Suit website.
There you'll be able to create this API itself, right?
And it is completely for free right now.
Google Gemini Pro and as you all know recently Google Gemini Pro has crossed GPT four.
Right now it is only below GPT four turbo, right?
Probably when we'll have Google Gemini Ultra, right.
So at that time, I think the accuracy will be pretty much good.
So over here you have your Google API key.
This is done in requirement dot txt.
I am going to probably load these three amazing libraries.
One is streamlit google dot generative AI python dot env.
Okay, so these are the three libraries that I will specifically require.
And as you know that we are going to create this as a large image model application, not an LM application.
Because here we are working with images.
So let's go ahead.
And first of all uh conda activate uh v and we will try to activate this okay.
So this is done I will clear my screen.
And now quickly we will go ahead and install our requirement dot txt pip install.
Oops.
Let's see.
Let me clear my screen.
So let me go ahead and write pip install requirements dot txt.
So once this requirement is probably uh what is this.
Requirements requirements pip install could not find the version that satisfies the requirement requirement
dot txt consider okay sorry this small mistakes will be there.
So it should be minus r.
Then only it will be able to find in that folder right.
So now all the requirement dot txt will start getting installed once this installation will happen.
That basically means this three important libraries will get installed inside this v and V folder.
Now till then, what I will do quickly let me go ahead and create my app.py file, because this will
basically be my uh, the main file which I will be writing the code now step by step, just think over
the app.
Right.
What we are specifically doing, we have to probably create an upload button where we specifically upload
the image.
And that image should interact with the Google Gemini Pro Vision API.
Right.
And along with this, I should also write my own custom prompt just to say like how this Google Gemini
Pro API should be working.
Okay, all those things will specifically be there.
So initially I will go ahead.
Let's wait till the installation will take place.
And then what I will specifically do is that first of all, I will quickly import all these important
libraries that I will be requiring.
One is Streamlit as St.
Then I will go ahead and write Google Dot generative AI.
I'll be importing Google dot generative AI as an AI.
I'll also be importing OS and then I will go ahead and import from dot env import load underscore dot
env.
Because with the help of load underscore dot env I will be loading all my environment variables.
So loading all the environment variables right.
So specifically we'll be using this.
So let me save this okay.
So the installation has been done.
So I will just go ahead and close this along with this.
Since I'm working with image I need to take out the image bytes probably convert into a different formats,
or take out some information from the image that I upload which will be required by the Google Gemini.
Okay, so all these things have specifically done and now you can see now all the highlighting is also
specifically working.
So I have loaded all the environments by using load underscore dot env.
Now the next thing is that I will go ahead and write gen I dot configure.
And here I will going to use my API key.
And the API key will I will basically call my API key over here.
Right.
So for this I will be using OS dot get env I will get the environment variables.
And inside this environment variable I will copy Google API key.
Right.
I will call this Google API key.
So this is what is my environment variable.
And this is the key that I require right.
This is my API key to interact with the Google Gemini Pro Vision API right.
So once I have done this so I've configured this.
Now the next thing is that I will go ahead and write get underscore Gemini underscore response.
And here I'm going to give two important parameters.
One is the input prompt.
The prompt that I am specifically giving and telling the Google Gemini Pro Vision API to act right.
I'll say that hey, you are an assistant, which will actually help me to take out this information
from the image and provide whether this food is healthy or not.
Such kind of messages.
Right?
And the second parameter that you really need to give over here is your image.
Okay.
So I have created this function over here.
And then the first thing that I will do is that call this model right.
So model is equal to Jen AI dot generative model.
And inside this I will call my model name.
So it will be Gemini Pro vision right.
So once we call this Gemini Pro vision that basically means we will this model only we have to use it
because this model will be responsible in working with images.
Okay.
And the next thing that I will do is that create my response.
And here I will write model dot generate content.
And here I'm just going to give my two parameters.
One is the input prompt.
And my second thing will be whichever is the image that I'm going to get those information.
And after this I'm going to specifically return my response dot text.
Right.
So this is my function that is doing all the tasks that is uh, interacting with the model, giving
the information of input prompt and images and getting that information back.
Right.
The next function that I really need to create is as soon as I upload the image, I should be able to
take out those image information in a format.
And this format is required because in this format, the Google Gemini Pro vision will be able to understand.
So here you'll be able to see this is the format definition input image setup I will be giving the uploaded
file.
If the uploaded file is not none then I will get the values.
I'll read the file into bytes.
So if I probably write uploaded file dot get value, I will get all the bytes information.
And then I have to convert this into a format which looks like this.
Right?
The image parts one is the Mime type.
Here I'm saying what is the type of the file.
And the second is in the form of data.
Now this format is the format that is specifically required by the Google Gemini Pro, right?
So initially as soon as I upload the images, I cannot directly give the image to my Google Gemini provision.
Right?
So from that image I will take out the bytes data.
And then we will convert this into in this format that is with Mime type and data as a key value pairs.
And then we will send this image part.
So this is my second function that I would be working on.
So this two important function is there.
The first function will be this and the second function.
Once I get that particular image parts I will send it to this specific function and get my response
text.
That is how simple it is right now.
The next thing is very much simple.
Uh, as you know, I require a upload button and I require a submit button, right.
So here I'm going to initialize my Streamlit app.
Okay.
So this will basically be my Streamlit app.
Now here I'm going to basically say this is my calories Advisor app okay advisor app.
So this is my app I'm saying uh s t dot header.
So let me just go ahead and write the same thing okay.
Done.
Then I have my uploaded file as t dot file uploaded.
Choose an image.
The type will be jpg jpg png okay.
And then here is my image.
If the uploaded file is not none, then what we are going to do as soon as we upload the file right?
The image should get opened below, like how I showed in the demo, right?
So that is the reason we are using this image dot open.
And then we are writing s t dot image and we are showing that image over there.
Okay.
And then finally we have the submit button.
Tell me about the calories.
Now is the main task.
So this is my front end setup.
You can probably say this is my front end.
Front end setup.
Back end also have created it.
Back end is this two function right now is the main thing.
And the parameter that we have written input prompt.
Because we need to tell how the Google Gemini Pro vision needs to work like.
So.
Here we have.
I have created an amazing prompt which will provide you this entire response.
So this is the prompt that we are specifically going to use.
You are an expert in newtonensis where you need to see the food items from the image and calculate the
total calories.
Also provide a detailed of every food items with the calorie intake in the below format item one number
of calories, item two number of calories, and so on.
Finally, you can also mention whether the food is healthy or not and also mention the percentage split
of ratio of carbohydrate, fats, fiber, sugar, and other important things that is required in our
diet.
Right?
So this is a kind of input prompt.
Now it is up to you.
However you specifically want to change the input prompt.
You can basically change it okay.
So this is what based on this input prompt, the Google Gemini Pro vision is going to act based on the
information that we are going to give over here.
Now it is up to you.
Whatever changes you specifically want over here, you can write it.
Now.
The next step, what we are going to do, I'm going to write if submit now if when I'm submitting the
button, the first thing is that I'm going to get my image data right now.
Image data I will get it from which function get uh or input input image setup.
And inside this particular image setup I need to probably give my uploaded file.
Right.
So uploaded file is basically there in this particular variable.
So once I give this I will be getting my image data.
Once I get my image data then what I need to do I need to give to my get Gemini response here I'm going
to give my input prompt.
Okay.
So this will basically be my input prompt.
I think the spelling is right.
And the second parameter is nothing.
But is my image data that I want to give right.
So once I get this I will get the response back two steps.
Now as soon as I get the response, I will probably just write s t dot header and s t dot write.
The response is whatever response I'm getting from you, right?
So this is my app overall.
And now you can see how easily we are able to do this.
And you can even deploy this in hugging face and try to see it okay.
Now once I save this now let's go to my terminal and let's run and see whether everything is working
fine or not.
If I get an error, that is good, but I will try to solve that error.
So Streamlit run app.py.
Okay, so yes it's running.
Let's see.
I will say allow access.
Great.
Now here is my entire thing.
Now let's start with some simple meal.
Okay, so this meal looks good.
Really good.
Um, it has broccolis.
It has some seeds.
It has chicken pieces, multiple things.
Now let me just go ahead and click on tell me about the calories.
Now see input prompt.
Whatever things you the main changes that you can really do.
Like how a Google Gemini Pro API should work like based on the input prompt right there.
You specifically require prompt engineering so it has calories.
Broccoli.
Tuna.
Sesame seeds.
Lime.
Orange.
The total calories for ten the meal is healthy option because it is imbalanced in terms of macronutrients.
It contains a variety of minerals uh, vitamins, right?
Vitamins and minerals.
The chicken provides good protein, broccoli and orange provides carbohydrate and fiber, and the sesame
seeds provide healthy fats.
The lime adds a touch of flavor and vitamin C, so every thing is there.
Now you can probably see right every day, you know?
See, nowadays I eat a lot of millets like bajra, Jabbar and all, and I have probably uploaded all
those images.
Right.
And it says that yes, it is a good diet.
And by that I feel a lot of comfortable in that.
Right.
And I'm working on the food things.
You know, we really need to have the right food.
And here is one of the amazing app which you can specifically use.
Okay.
So yes, this was it.
Uh, all the information regarding this will be given in the description of this particular video.
I'll see you all in the next video.
Have a great day.
Thank you and all.
Take care.
Bye bye.