nrohan988 commited on
Commit
24e786d
β€’
1 Parent(s): be3fb06

Upload 2 files

Browse files
Files changed (2) hide show
  1. app.py +68 -0
  2. requirements.txt +3 -0
app.py ADDED
@@ -0,0 +1,68 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import streamlit as st
2
+ import google.generativeai as genai
3
+ import os
4
+ from dotenv import load_dotenv
5
+ load_dotenv()
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
+
17
+ if uploaded_file is not None:
18
+ bytes_data = uploaded_file.getvalue()
19
+
20
+ image_parts = [
21
+ {
22
+ "mime_type": uploaded_file.type,
23
+ "data": bytes_data
24
+ }
25
+ ]
26
+
27
+ return image_parts
28
+
29
+ else:
30
+ raise FileNotFoundError("No file uploaded")
31
+
32
+
33
+ #initialize the streamlit app
34
+
35
+ st.set_page_config(page_title="Vijay: Food App πŸ‘¨β€βš•οΈ")
36
+
37
+ st.header("Vijay: Food App πŸ‘¨β€βš•οΈ")
38
+ st.subheader("Powered By Gemini")
39
+ uploaded_file = st.file_uploader("Choose an image...", type=["jpg", "jpeg", "png"])
40
+ image = ""
41
+
42
+ if uploaded_file is not None:
43
+ image = Image.open(uploaded_file)
44
+ st.image(image, caption="Uploaded Image.", use_column_width=True)
45
+
46
+ submit = st.button("Tell me about the total calories")
47
+
48
+ input_prompt="""
49
+ You are an expert in nutritionist where you need to see the food items from the image
50
+ and calculate the total calories, also provide the details of every food items with calories intake
51
+ is below format
52
+
53
+ 1. Item 1 - no of calories
54
+ 2. Item 2 - no of calories
55
+ ----
56
+ ----
57
+
58
+
59
+ """
60
+
61
+ ## If submit button is clicked
62
+
63
+ if submit:
64
+ image_data=input_image_setup(uploaded_file)
65
+ response=get_gemini_response(input_prompt,image_data,input)
66
+ st.subheader("The Response is")
67
+ st.write(response)
68
+
requirements.txt ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ streamlit
2
+ google.generativeai
3
+ python-dotenv