decodingdatascience commited on
Commit
d7c469d
·
verified ·
1 Parent(s): 3c6738e

Upload 2 files

Browse files
Files changed (2) hide show
  1. app.py +74 -0
  2. requirements.txt +9 -0
app.py ADDED
@@ -0,0 +1,74 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ### Health Management APP
2
+ from dotenv import load_dotenv
3
+
4
+ load_dotenv() ## load all the environment variables
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
+ ## Function to load Google Gemini Pro Vision API And get response
14
+
15
+ def get_gemini_repsonse(input,image,prompt):
16
+ model=genai.GenerativeModel('gemini-pro-vision')
17
+ response=model.generate_content([input,image[0],prompt])
18
+ return response.text
19
+
20
+ def input_image_setup(uploaded_file):
21
+ # Check if a file has been uploaded
22
+ if uploaded_file is not None:
23
+ # Read the file into bytes
24
+ bytes_data = uploaded_file.getvalue()
25
+
26
+ image_parts = [
27
+ {
28
+ "mime_type": uploaded_file.type, # Get the mime type of the uploaded file
29
+ "data": bytes_data
30
+ }
31
+ ]
32
+ return image_parts
33
+ else:
34
+ raise FileNotFoundError("No file uploaded")
35
+
36
+ ##initialize our streamlit app
37
+
38
+ st.set_page_config(page_title="DDS Health App")
39
+
40
+ st.header("DDS Health App")
41
+ input=st.text_input("Input Prompt: ",key="input")
42
+ uploaded_file = st.file_uploader("Choose an image...", type=["jpg", "jpeg", "png"])
43
+ image=""
44
+ if uploaded_file is not None:
45
+ image = Image.open(uploaded_file)
46
+ st.image(image, caption="Uploaded Image.", use_column_width=True)
47
+
48
+
49
+ submit=st.button("Tell me the total calories & Nutirients")
50
+
51
+ input_prompt="""
52
+ You are an expert in nutritionist where you need to see the food items from the image
53
+ and calculate the total calories, also provide the details of every food items with calories intake
54
+ is below format
55
+
56
+ 1. Item 1 - no of calories
57
+ 2. Item 2 - no of calories
58
+ ----
59
+ ----
60
+ Total Calories
61
+
62
+ Also mention about the important nutirnts like Protien , Carbohydrates and Fats in each item
63
+
64
+ Put the output in a tabular format with each item in a seperate row and details in columns
65
+ """
66
+
67
+ ## If submit button is clicked
68
+
69
+ if submit:
70
+ image_data=input_image_setup(uploaded_file)
71
+ response=get_gemini_repsonse(input_prompt,image_data,input)
72
+ st.subheader("The Response is")
73
+ st.write(response)
74
+
requirements.txt ADDED
@@ -0,0 +1,9 @@
 
 
 
 
 
 
 
 
 
 
1
+ streamlit
2
+ google-generativeai
3
+ python-dotenv
4
+ langchain
5
+ PyPDF2
6
+ chromadb
7
+ pdf2image
8
+ faiss-cpu
9
+ langchain_google_genai