Spaces:
Runtime error
Runtime error
Upload 3 files
Browse files- .env +1 -0
- app.py +78 -0
- requirements.txt +9 -0
.env
ADDED
@@ -0,0 +1 @@
|
|
|
|
|
1 |
+
GOOGLE_API_KEY = "AIzaSyDDP5cdZHazApV_xPjdqhG4_zb5x6Li4nM"
|
app.py
ADDED
@@ -0,0 +1,78 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
### HeartFuel NutriGuide 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 |
+
# Set the page title
|
39 |
+
st.set_page_config(page_title="HeartFuel NutriGuide")
|
40 |
+
|
41 |
+
# Colorful header
|
42 |
+
st.markdown("<h1 style='color: #009933;'>HeartFuel NutriGuide</h1>", unsafe_allow_html=True)
|
43 |
+
|
44 |
+
# Colorful text
|
45 |
+
st.markdown("<span style='color:#0066cc;'>**Regulating food intake for CVD Risk patients**</span><br>by <span style='color:#ff3399;'>***Chidozie Louis Uzoegwu***</span>", unsafe_allow_html=True)
|
46 |
+
|
47 |
+
|
48 |
+
input=st.text_input("Ask any Question about this food: ",key="input")
|
49 |
+
uploaded_file = st.file_uploader("Choose an image...", type=["jpg", "jpeg", "png"])
|
50 |
+
image=""
|
51 |
+
if uploaded_file is not None:
|
52 |
+
image = Image.open(uploaded_file)
|
53 |
+
st.image(image, caption="Uploaded Image.", use_column_width=True)
|
54 |
+
|
55 |
+
|
56 |
+
submit=st.button("Calculate Nutrition Profile")
|
57 |
+
|
58 |
+
input_prompt="""
|
59 |
+
As a nutritionist specializing in cardiovascular health, your task is to analyze the nutritional content of the food items in the provided image. For each item, list the following nutrients in a table:
|
60 |
+
|
61 |
+
Food Item
|
62 |
+
Calories
|
63 |
+
Omega-3 (mg)
|
64 |
+
Fiber (g)
|
65 |
+
Antioxidants
|
66 |
+
Potassium (mg)
|
67 |
+
Magnesium (mg)
|
68 |
+
After listing the nutrients, provide a summary of the overall impact of these nutrients on heart health. If any items are found to be less than ideal, suggest alternative heart-healthy options.
|
69 |
+
"""
|
70 |
+
|
71 |
+
## If submit button is clicked
|
72 |
+
|
73 |
+
if submit:
|
74 |
+
image_data=input_image_setup(uploaded_file)
|
75 |
+
response=get_gemini_repsonse(input_prompt,image_data,input)
|
76 |
+
st.markdown("**<h3 style='color: blue;'>RESULT:</h3>**", unsafe_allow_html=True)
|
77 |
+
st.write(response)
|
78 |
+
|
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
|