Files changed (1) hide show
  1. app.py +72 -72
app.py CHANGED
@@ -1,73 +1,73 @@
1
- from dotenv import load_dotenv
2
- load_dotenv()
3
-
4
- import streamlit as st
5
- import google.generativeai as genai
6
- import os
7
- from PIL import Image
8
- #from PyPDF2 import PdfReader
9
-
10
- genai.configure(api_key=os.getenv("GOOGLE_API_KEY"))
11
-
12
- def get_gemini_response(input_prompt,image):
13
- model=genai.GenerativeModel("gemini-pro-vision")
14
- response=model.generate_content([input_prompt,image[0]])
15
- return response.text
16
-
17
-
18
- def get_image_content(uploaded_file):
19
- if uploaded_file is not None:
20
- image_byte_data=uploaded_file.getvalue()
21
-
22
- image_parts = [
23
- {
24
- "mime_type":uploaded_file.type,
25
- "data":image_byte_data
26
- }
27
- ]
28
- return image_parts
29
- else:
30
- raise FileNotFoundError("File not uploaded")
31
-
32
-
33
- st.set_page_config(page_title="FoodAnalyzer")
34
- st.markdown("<h1 style='text-align: center;'>FoodAnalyzer App</h1>", unsafe_allow_html=True)
35
-
36
- age = st.number_input("Enter Age", min_value=0, max_value=120, step=1)
37
- gender = st.selectbox("Select Gender", options=["Male", "Female", "Other"])
38
- weight = st.number_input("Enter Weight in (kg)", min_value=0.0, step=0.1)
39
- Height = st.number_input("Enter Height in (cm)", min_value=0.0, step=0.1)
40
-
41
- uploaded_file=st.file_uploader("Upload an Image",type=["jpg","png","jpeg"])
42
- image=''
43
- if uploaded_file is not None:
44
- image=Image.open(uploaded_file)
45
- st.image(image, caption="Uploaded Image", use_column_width=True)
46
-
47
- col1, col2, col3 = st.columns([7, 2, 7])
48
- with col2:
49
- submit = st.button("Analyze")
50
-
51
- input_prompt = f"""
52
- You are an expert nutritionist. Please analyze the food items from the uploaded image and calculate the
53
- total calories. Also provide the details of every food item with calorie intake in the following format:
54
-
55
- 1. Item 1 - Number of calories
56
- 2. Item 2 - Number of calories
57
- 3. Item 3 - Number of calories
58
- 4. Item 4 - Number of calories
59
- ......
60
- ......
61
-
62
- Also, consider the user inputted {age}, {gender}, {weight}, {Height} and mention whether the food is healthy or not
63
- for the inputted {age}, {gender}, {weight},{Height}. Additionally, mention the percentage split of the ratio of proteins, carbohydrates, fats, fiber, sugar, minerals, vitamins, and
64
- other important nutrients required in our diet. Do not confuse and show {weight} with {Height} or {Height} with {weight}"""
65
-
66
-
67
- if submit:
68
- image_date = get_image_content(uploaded_file)
69
- response=get_gemini_response(input_prompt,image_date)
70
- st.subheader("The Response is")
71
- st.write(response)
72
-
73
 
 
1
+ from dotenv import load_dotenv
2
+ load_dotenv()
3
+
4
+ import streamlit as st
5
+ import google.generativeai as genai
6
+ import os
7
+ from PIL import Image
8
+ #from PyPDF2 import PdfReader
9
+
10
+ genai.configure(api_key=os.getenv("GOOGLE_API_KEY"))
11
+
12
+ def get_gemini_response(input_prompt,image):
13
+ model=genai.GenerativeModel("gemini-pro-1.5-latest")
14
+ response=model.generate_content([input_prompt,image[0]])
15
+ return response.text
16
+
17
+
18
+ def get_image_content(uploaded_file):
19
+ if uploaded_file is not None:
20
+ image_byte_data=uploaded_file.getvalue()
21
+
22
+ image_parts = [
23
+ {
24
+ "mime_type":uploaded_file.type,
25
+ "data":image_byte_data
26
+ }
27
+ ]
28
+ return image_parts
29
+ else:
30
+ raise FileNotFoundError("File not uploaded")
31
+
32
+
33
+ st.set_page_config(page_title="FoodAnalyzer")
34
+ st.markdown("<h1 style='text-align: center;'>FoodAnalyzer App</h1>", unsafe_allow_html=True)
35
+
36
+ age = st.number_input("Enter Age", min_value=0, max_value=120, step=1)
37
+ gender = st.selectbox("Select Gender", options=["Male", "Female", "Other"])
38
+ weight = st.number_input("Enter Weight in (kg)", min_value=0.0, step=0.1)
39
+ Height = st.number_input("Enter Height in (cm)", min_value=0.0, step=0.1)
40
+
41
+ uploaded_file=st.file_uploader("Upload an Image",type=["jpg","png","jpeg"])
42
+ image=''
43
+ if uploaded_file is not None:
44
+ image=Image.open(uploaded_file)
45
+ st.image(image, caption="Uploaded Image", use_column_width=True)
46
+
47
+ col1, col2, col3 = st.columns([7, 2, 7])
48
+ with col2:
49
+ submit = st.button("Analyze")
50
+
51
+ input_prompt = f"""
52
+ You are an expert nutritionist. Please analyze the food items from the uploaded image and calculate the
53
+ total calories. Also provide the details of every food item with calorie intake in the following format:
54
+
55
+ 1. Item 1 - Number of calories
56
+ 2. Item 2 - Number of calories
57
+ 3. Item 3 - Number of calories
58
+ 4. Item 4 - Number of calories
59
+ ......
60
+ ......
61
+
62
+ Also, consider the user inputted {age}, {gender}, {weight}, {Height} and mention whether the food is healthy or not
63
+ for the inputted {age}, {gender}, {weight},{Height}. Additionally, mention the percentage split of the ratio of proteins, carbohydrates, fats, fiber, sugar, minerals, vitamins, and
64
+ other important nutrients required in our diet. Do not confuse and show {weight} with {Height} or {Height} with {weight}"""
65
+
66
+
67
+ if submit:
68
+ image_date = get_image_content(uploaded_file)
69
+ response=get_gemini_response(input_prompt,image_date)
70
+ st.subheader("The Response is")
71
+ st.write(response)
72
+
73