arnabbumba077 commited on
Commit
2fa458c
·
verified ·
1 Parent(s): 3524dbe

Upload 3 files

Browse files
Files changed (3) hide show
  1. .env +1 -0
  2. app.py +63 -0
  3. requirements.txt +3 -0
.env ADDED
@@ -0,0 +1 @@
 
 
1
+ GOOGLE_API_KEY="AIzaSyAJjp2hRJBGsei-o6kfvnZ8EeKkXl4-XuI"
app.py ADDED
@@ -0,0 +1,63 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import streamlit as st
2
+ import google.generativeai as genai
3
+ import os
4
+ from dotenv import load_dotenv
5
+ load_dotenv() # loading all the environment variables
6
+ from PIL import Image
7
+
8
+ genai.configure(api_key=os.getenv("GOOGLE_API_KEY"))
9
+
10
+ def get_gemini_response(input_prompt,image):
11
+ model=genai.GenerativeModel('gemini-pro-vision')
12
+ response=model.generate_content([input_prompt,image[0]])
13
+ return response.text
14
+
15
+ def input_image_setup(uploaded_file):
16
+ # Check if a file has been uploaded
17
+ if uploaded_file is not None:
18
+ # Read the file into bytes
19
+ bytes_data=uploaded_file.getvalue()
20
+
21
+ image_parts=[
22
+ {
23
+ "mime_type": uploaded_file.type, # Get the mime type of the uploaded file
24
+ "data": bytes_data
25
+ }
26
+ ]
27
+ return image_parts
28
+ else:
29
+ raise FileNotFoundError("No file uploaded")
30
+
31
+ ## initialize our streamlit app
32
+
33
+ st.set_page_config(page_title="Calorie Advisor App")
34
+
35
+ st.header("Calorie Advisor App")
36
+ uploaded_file=st.file_uploader("Choose an image...", type=["jpg","jpeg","png"])
37
+ image=""
38
+ if uploaded_file is not None:
39
+ image=Image.open(uploaded_file)
40
+ st.image(image,caption="Uploaded Image.", use_column_width=True)
41
+
42
+ submit=st.button("Tell me about the total calories")
43
+
44
+ input_prompt="""
45
+ You are an expert in nutrition. You need to see the food items from the image
46
+ and calculate the total calories. Provide the details of every
47
+ food item with calories intake in below format
48
+
49
+ 1. Item 1 - no. of calories
50
+ 2. Item 2 - no. of calories
51
+ ----
52
+ ----
53
+ Finally, mention whether the food is health or not and also mention the
54
+ percentage split of carbohydrates,proteins,fats,fibers,sugar and other
55
+ things required in our diet.
56
+
57
+ """
58
+
59
+ if submit:
60
+ image_data=input_image_setup(uploaded_file)
61
+ response=get_gemini_response(input_prompt,image_data)
62
+ st.header("The Response is")
63
+ st.write(response)
requirements.txt ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ streamlit
2
+ google-generativeai
3
+ python-dotenv