Create app.py
Browse files
app.py
ADDED
@@ -0,0 +1,50 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import streamlit as st
|
2 |
+
import google.generativeai as genai
|
3 |
+
from PIL import Image
|
4 |
+
import os
|
5 |
+
|
6 |
+
genai.configure(api_key = os.getenv('GOOGLE_API_KEY'))
|
7 |
+
|
8 |
+
model=genai.GenerativeModel('gemini-1.5-pro-latest')
|
9 |
+
input_prompt = """
|
10 |
+
As a doctor specialized in healthcare, analyze the base contents of the food, if there are allergens warn about the risks and potential harm of the food, then recommend healthy food and exercies to balance the diet.
|
11 |
+
Output structure:
|
12 |
+
Start and end with (```)
|
13 |
+
"""
|
14 |
+
|
15 |
+
def generate_response(input_prompt,image):
|
16 |
+
response = model.generate_content([input_prompt,image[0]])
|
17 |
+
# print(response.text)
|
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 |
+
st.title("Hackaton DemoGround")
|
37 |
+
st.text("Upload food image here:")
|
38 |
+
|
39 |
+
upload_file = st.file_uploader('',type=['jpg','jpeg','png'])
|
40 |
+
if upload_file is not None:
|
41 |
+
image = Image.open(upload_file)
|
42 |
+
st.image(image, caption="Uploaded Image", use_column_width=True)
|
43 |
+
|
44 |
+
submit = st.button('Analyze Contents')
|
45 |
+
if submit:
|
46 |
+
image_data = input_image_setup(uploaded_file=upload_file)
|
47 |
+
with st.spinner("Analyzing the contents..."):
|
48 |
+
response = generate_response(input_prompt, image_data)
|
49 |
+
st.subheader("OUTPUT:")
|
50 |
+
st.markdown(response)
|