Spaces:
Sleeping
Sleeping
Jaichandran1984
commited on
Commit
•
2ac5e9e
1
Parent(s):
9d1855c
Update app.py
Browse files
app.py
CHANGED
@@ -1,60 +1,60 @@
|
|
1 |
-
from dotenv import load_dotenv
|
2 |
-
load_dotenv()
|
3 |
-
|
4 |
-
import streamlit as st
|
5 |
-
import google.generativeai as genai
|
6 |
-
import os
|
7 |
-
from PIL import Image
|
8 |
-
#from PyPDF2 import PdfReader
|
9 |
-
|
10 |
-
genai.configure(api_key=os.getenv("
|
11 |
-
|
12 |
-
def get_gemini_response(input_prompt,image):
|
13 |
-
model=genai.GenerativeModel("gemini-pro-vision")
|
14 |
-
response=model.generate_content([input_prompt,image[0]])
|
15 |
-
return response.text
|
16 |
-
|
17 |
-
|
18 |
-
def get_image_content(uploaded_file):
|
19 |
-
if uploaded_file is not None:
|
20 |
-
image_byte_data=uploaded_file.getvalue()
|
21 |
-
|
22 |
-
image_parts = [
|
23 |
-
{
|
24 |
-
"mime_type":uploaded_file.type,
|
25 |
-
"data":image_byte_data
|
26 |
-
}
|
27 |
-
]
|
28 |
-
return image_parts
|
29 |
-
else:
|
30 |
-
raise FileNotFoundEroor("File not uploaded")
|
31 |
-
|
32 |
-
st.header("Healthify App")
|
33 |
-
uploaded_file=st.file_uploader("Upload an Image",type=["jpg","png","jpeg"])
|
34 |
-
image=''
|
35 |
-
if uploaded_file is not None:
|
36 |
-
image=Image.open(uploaded_file)
|
37 |
-
st.image(image, caption="Upload Image", use_column_width=True)
|
38 |
-
|
39 |
-
submit=st.button("Click here to know total calories of the uploaded image")
|
40 |
-
|
41 |
-
input_prompt = """
|
42 |
-
You are an expert in nutritionist where you need to see the food items from the uploaded image
|
43 |
-
and calculate the total calroies, also provide the details of every food items with calories intake
|
44 |
-
in the below formt
|
45 |
-
|
46 |
-
1. Item 1 - No of calories
|
47 |
-
2. Item 2 - No of calories
|
48 |
-
......
|
49 |
-
......
|
50 |
-
|
51 |
-
finally you can also mention whethere the food is healthy or not and also
|
52 |
-
mention the percentage split of the ratio of protains,carbohydrates,fats,fiber,sugar,minerals,vitamins and
|
53 |
-
other import things required in our diet
|
54 |
-
"""
|
55 |
-
|
56 |
-
if submit:
|
57 |
-
image_date = get_image_content(uploaded_file)
|
58 |
-
response=get_gemini_response(input_prompt,image_date)
|
59 |
-
st.markdown("The Response is")
|
60 |
st.write(response)
|
|
|
1 |
+
from dotenv import load_dotenv
|
2 |
+
load_dotenv()
|
3 |
+
|
4 |
+
import streamlit as st
|
5 |
+
import google.generativeai as genai
|
6 |
+
import os
|
7 |
+
from PIL import Image
|
8 |
+
#from PyPDF2 import PdfReader
|
9 |
+
|
10 |
+
genai.configure(api_key=os.getenv("AIzaSyC6b_XsB8ibEkzG-ax0BuLj3TUpta_y0Ts"))
|
11 |
+
|
12 |
+
def get_gemini_response(input_prompt,image):
|
13 |
+
model=genai.GenerativeModel("gemini-pro-vision")
|
14 |
+
response=model.generate_content([input_prompt,image[0]])
|
15 |
+
return response.text
|
16 |
+
|
17 |
+
|
18 |
+
def get_image_content(uploaded_file):
|
19 |
+
if uploaded_file is not None:
|
20 |
+
image_byte_data=uploaded_file.getvalue()
|
21 |
+
|
22 |
+
image_parts = [
|
23 |
+
{
|
24 |
+
"mime_type":uploaded_file.type,
|
25 |
+
"data":image_byte_data
|
26 |
+
}
|
27 |
+
]
|
28 |
+
return image_parts
|
29 |
+
else:
|
30 |
+
raise FileNotFoundEroor("File not uploaded")
|
31 |
+
|
32 |
+
st.header("Healthify App")
|
33 |
+
uploaded_file=st.file_uploader("Upload an Image",type=["jpg","png","jpeg"])
|
34 |
+
image=''
|
35 |
+
if uploaded_file is not None:
|
36 |
+
image=Image.open(uploaded_file)
|
37 |
+
st.image(image, caption="Upload Image", use_column_width=True)
|
38 |
+
|
39 |
+
submit=st.button("Click here to know total calories of the uploaded image")
|
40 |
+
|
41 |
+
input_prompt = """
|
42 |
+
You are an expert in nutritionist where you need to see the food items from the uploaded image
|
43 |
+
and calculate the total calroies, also provide the details of every food items with calories intake
|
44 |
+
in the below formt
|
45 |
+
|
46 |
+
1. Item 1 - No of calories
|
47 |
+
2. Item 2 - No of calories
|
48 |
+
......
|
49 |
+
......
|
50 |
+
|
51 |
+
finally you can also mention whethere the food is healthy or not and also
|
52 |
+
mention the percentage split of the ratio of protains,carbohydrates,fats,fiber,sugar,minerals,vitamins and
|
53 |
+
other import things required in our diet
|
54 |
+
"""
|
55 |
+
|
56 |
+
if submit:
|
57 |
+
image_date = get_image_content(uploaded_file)
|
58 |
+
response=get_gemini_response(input_prompt,image_date)
|
59 |
+
st.markdown("The Response is")
|
60 |
st.write(response)
|