File size: 1,823 Bytes
2ac5e9e
 
 
 
 
 
 
 
 
185ebf3
2ac5e9e
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
3f91e23
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
from dotenv import load_dotenv
load_dotenv()

import streamlit as st
import google.generativeai as genai 
import os
from PIL import Image 
#from PyPDF2 import PdfReader

genai.configure(api_key=os.getenv("GOOGLE_API_KEY"))

def get_gemini_response(input_prompt,image):
    model=genai.GenerativeModel("gemini-pro-vision")
    response=model.generate_content([input_prompt,image[0]])
    return response.text


def get_image_content(uploaded_file):
    if uploaded_file is not None:
        image_byte_data=uploaded_file.getvalue()

        image_parts = [
            {   
                "mime_type":uploaded_file.type, 
                "data":image_byte_data
            }
        ]
        return image_parts
    else:
        raise FileNotFoundEroor("File not uploaded") 

st.header("Healthify App")  
uploaded_file=st.file_uploader("Upload an Image",type=["jpg","png","jpeg"])   
image=''
if uploaded_file is not None:
    image=Image.open(uploaded_file)
    st.image(image, caption="Upload Image", use_column_width=True)

submit=st.button("Click here to know total calories of the uploaded image")

input_prompt = """
You are an expert in nutritionist where you need to see the food items from the uploaded image
and calculate the total calroies, also provide the details of every food items with calories intake
in the below formt

     1. Item 1 - No of calories
     2. Item 2 - No of calories  
......
......

finally you can also mention whethere the food is healthy or not and also
mention the percentage split of the ratio of protains,carbohydrates,fats,fiber,sugar,minerals,vitamins and
other import things required in our diet
"""

if submit:
    image_date = get_image_content(uploaded_file)
    response=get_gemini_response(input_prompt,image_date)
    st.markdown("The Response is")
    st.write(response)