JishnuSetia commited on
Commit
226a9a0
1 Parent(s): a1bb2c3

Upload 2 files

Browse files
Files changed (2) hide show
  1. app.py +61 -0
  2. requirements.txt +8 -0
app.py ADDED
@@ -0,0 +1,61 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ### Health Management APP
2
+ from dotenv import load_dotenv
3
+
4
+ load_dotenv()
5
+
6
+ import streamlit as st
7
+ import os
8
+ import google.generativeai as genai
9
+ from PIL import Image
10
+
11
+ genai.configure(api_key=os.getenv("GOOGLE_API_KEY"))
12
+
13
+ def get_gemini_repsonse(input,image,prompt):
14
+ model=genai.GenerativeModel('gemini-pro-vision')
15
+ response=model.generate_content([input,image[0],prompt])
16
+ return response.text
17
+
18
+ def input_image_setup(uploaded_file):
19
+ if uploaded_file is not None:
20
+ bytes_data = uploaded_file.getvalue()
21
+
22
+ image_parts = [
23
+ {
24
+ "mime_type": uploaded_file.type,
25
+ "data": bytes_data
26
+ }
27
+ ]
28
+ return image_parts
29
+ else:
30
+ raise FileNotFoundError("No file uploaded")
31
+
32
+ st.set_page_config(page_title="AI Nutrtitionist")
33
+ st.header("AI Nutrtitionist")
34
+ input=st.text_input("Input Prompt: ",key="input")
35
+ uploaded_file = st.file_uploader("Choose an image...", 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
+
42
+ submit=st.button("Tell me the total calories & Nutirients")
43
+
44
+ input_prompt="""
45
+ You are an expert in nutritionist where you need to see the food items from the image
46
+ and calculate the total calories, also provide the details of every food items with calories intake
47
+ is below format
48
+ 1. Item 1 - no of calories
49
+ 2. Item 2 - no of calories
50
+ ----
51
+ ----
52
+ Total Calories
53
+ Also mention about the important nutirnts like Protien , Carbohydrates and Fats in each item
54
+ Put the output in a tabular format with each item in a seperate row and details in columns
55
+ """
56
+
57
+ if submit:
58
+ image_data=input_image_setup(uploaded_file)
59
+ response=get_gemini_repsonse(input_prompt,image_data,input)
60
+ st.subheader("The Response is")
61
+ st.write(response)
requirements.txt ADDED
@@ -0,0 +1,8 @@
 
 
 
 
 
 
 
 
 
1
+ streamlit
2
+ google-generativeai
3
+ python-dotenv
4
+ langchain
5
+ PyPDF2
6
+ chromadb
7
+ pdf2image
8
+ langchain_google_genai