vplearnstocode commited on
Commit
4e38514
·
verified ·
1 Parent(s): 78cc2e2

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +65 -0
app.py ADDED
@@ -0,0 +1,65 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import os
2
+ import google.generativeai as genai
3
+ import streamlit as st
4
+ from dotenv import load_dotenv, find_dotenv
5
+ from PIL import Image
6
+
7
+ load_dotenv(find_dotenv())
8
+
9
+ genai.configure(api_key=os.getenv("GOOGLE_API_KEY"))
10
+
11
+ def get_gemini_response(input, image):
12
+ model = genai.GenerativeModel("gemini-1.5-pro-latest")
13
+ response = model.generate_content([input,image[0]])
14
+ return response.text
15
+
16
+
17
+ def input_image_setup(uploaded_file):
18
+ # check if a file has been uploaded
19
+ if uploaded_file is not None:
20
+ bytes_data = uploaded_file.getvalue()
21
+ image_parts = [
22
+ {
23
+ "mime_type": uploaded_file.type,
24
+ "data": bytes_data,
25
+ }
26
+ ]
27
+ return image_parts
28
+ else:
29
+ raise FileNotFoundError("No file uploaded")
30
+
31
+
32
+ st.set_page_config(page_title="Vaibhav's Nutrition Monitor", page_icon="🔮")
33
+ st.header("Vaibhav's Nutrition Monitor")
34
+ # input=st.text_input("Input Prompt: ",key="input")
35
+ uploaded_file = st.file_uploader("Upload an image of the food item", type=["jpg", "jpeg", "png"])
36
+ image = ""
37
+ if uploaded_file is not None:
38
+ image = Image.open(uploaded_file)
39
+ st.image(image, caption='Uploaded Image.', use_column_width=True)
40
+
41
+ submit = st.button("Tell me about total calories")
42
+
43
+ input_prompt="""
44
+ You are an expert in nutritionist where you need to see the food items from the image
45
+ and calculate the total calories, also provide the details of every food items with calories intake
46
+ is below format
47
+
48
+ 1. Item 1 - no of calories
49
+ 2. Item 2 - no of calories
50
+ ----
51
+ ----
52
+
53
+ Finally you can also mention whether the food is healthy or not. Mention the percentage
54
+ split of protein, carbs and fats in the food item. Mention total fiber content in the food item.
55
+ Also mention any other important details about the food item.
56
+
57
+ """
58
+
59
+ ## If submit button is clicked
60
+
61
+ if submit:
62
+ image_data=input_image_setup(uploaded_file)
63
+ response= get_gemini_response(input_prompt,image_data)
64
+ st.subheader("Food Analysis:")
65
+ st.write(response)