Upload 5 files
Browse files- .gitattributes +3 -0
- anna-pelzer-IGfIGP5ONV0-unsplash.jpg +3 -0
- app.py +82 -0
- nikolay-smeh-gPpbFaEkl00-unsplash.jpg +3 -0
- pexels-marvin-ozz-2474658.jpg +3 -0
- requirements.txt +7 -0
.gitattributes
CHANGED
@@ -33,3 +33,6 @@ saved_model/**/* filter=lfs diff=lfs merge=lfs -text
|
|
33 |
*.zip filter=lfs diff=lfs merge=lfs -text
|
34 |
*.zst filter=lfs diff=lfs merge=lfs -text
|
35 |
*tfevents* filter=lfs diff=lfs merge=lfs -text
|
|
|
|
|
|
|
|
33 |
*.zip filter=lfs diff=lfs merge=lfs -text
|
34 |
*.zst filter=lfs diff=lfs merge=lfs -text
|
35 |
*tfevents* filter=lfs diff=lfs merge=lfs -text
|
36 |
+
anna-pelzer-IGfIGP5ONV0-unsplash.jpg filter=lfs diff=lfs merge=lfs -text
|
37 |
+
nikolay-smeh-gPpbFaEkl00-unsplash.jpg filter=lfs diff=lfs merge=lfs -text
|
38 |
+
pexels-marvin-ozz-2474658.jpg filter=lfs diff=lfs merge=lfs -text
|
anna-pelzer-IGfIGP5ONV0-unsplash.jpg
ADDED
![]() |
Git LFS Details
|
app.py
ADDED
@@ -0,0 +1,82 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import streamlit as st
|
2 |
+
import os
|
3 |
+
from langchain_google_genai import GoogleGenerativeAIEmbeddings
|
4 |
+
import google.generativeai as genai
|
5 |
+
from langchain_google_genai import ChatGoogleGenerativeAI
|
6 |
+
from dotenv import load_dotenv
|
7 |
+
from PIL import Image
|
8 |
+
import google.generativeai as genai
|
9 |
+
|
10 |
+
load_dotenv()
|
11 |
+
genai.configure(api_key=os.getenv("GOOGLE_API_KEY"))
|
12 |
+
|
13 |
+
|
14 |
+
# Load Gemini pro vision
|
15 |
+
|
16 |
+
model = genai.GenerativeModel("gemini-pro-vision")
|
17 |
+
|
18 |
+
def get_final_response(system_prompt,input_image,user_prompt):
|
19 |
+
response = model.generate_content([system_prompt,input_image[0],user_prompt])
|
20 |
+
for candidate in response.candidates:
|
21 |
+
return [part.text for part in candidate.content.parts][0]
|
22 |
+
#return response.text
|
23 |
+
|
24 |
+
def image_processing(upload_file):
|
25 |
+
"""
|
26 |
+
This function converts the image in bytes
|
27 |
+
"""
|
28 |
+
|
29 |
+
if upload_file is not None:
|
30 |
+
data_bytes = upload_file.getvalue()
|
31 |
+
image_parts = [
|
32 |
+
{
|
33 |
+
"mime_type" : upload_file.type,
|
34 |
+
"data" : data_bytes
|
35 |
+
}
|
36 |
+
]
|
37 |
+
return image_parts
|
38 |
+
else:
|
39 |
+
raise FileNotFoundError("No file is uploaded.")
|
40 |
+
|
41 |
+
system_prompt = """
|
42 |
+
You're developing an advanced nutritional analysis tool that uses image recognition technology to estimate calorie intake from food images.
|
43 |
+
The system should be capable of accurately identifying different types of food items in an image and calculating the total calorie intake as well as providing a breakdown
|
44 |
+
of calorie counts for each food item detected. At the same time keep a count of quantity of each item and calculate calorie accordingly.
|
45 |
+
|
46 |
+
The system will accept food images as input and return the following output (in bullet points):
|
47 |
+
|
48 |
+
|
49 |
+
Total calories : Sum of calories of all food item
|
50 |
+
1. Food item 1 (Quantity): Calorie count of food item 1
|
51 |
+
2. Food item 2 (Quantity): Calorie count of food item 2
|
52 |
+
3. Food item 3 (Quantity): Calorie count of food item 3
|
53 |
+
.
|
54 |
+
.
|
55 |
+
. and so on..
|
56 |
+
|
57 |
+
"""
|
58 |
+
|
59 |
+
## Stremlit code:
|
60 |
+
|
61 |
+
st.set_page_config(page_title="Nutritional Model πΏπ")
|
62 |
+
|
63 |
+
st.header("Calorie Analysis ππ")
|
64 |
+
input = st.text_input("Input Prompt: ", key= "user_prompt")
|
65 |
+
upload_file = st.file_uploader("Upload your Food Image", type = ["jpg", "jpeg", "png"])
|
66 |
+
submit = st.button("Generate Calorie Analysis")
|
67 |
+
|
68 |
+
image = ""
|
69 |
+
|
70 |
+
if submit:
|
71 |
+
image_data = image_processing(upload_file)
|
72 |
+
response = get_final_response(system_prompt,image_data,input)
|
73 |
+
st.subheader("See Calorie Analysis below : ")
|
74 |
+
st.success(response)
|
75 |
+
|
76 |
+
if upload_file is not None:
|
77 |
+
image = Image.open(upload_file)
|
78 |
+
st.image(image, caption = "Uploaded image",width=500)
|
79 |
+
|
80 |
+
|
81 |
+
|
82 |
+
|
nikolay-smeh-gPpbFaEkl00-unsplash.jpg
ADDED
![]() |
Git LFS Details
|
pexels-marvin-ozz-2474658.jpg
ADDED
![]() |
Git LFS Details
|
requirements.txt
ADDED
@@ -0,0 +1,7 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
streamlit
|
2 |
+
google-generativeai
|
3 |
+
python-dotenv
|
4 |
+
langchain
|
5 |
+
PyPDF2
|
6 |
+
chromadb
|
7 |
+
langchain_google_genai
|