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