Food_Quality / app.py
irfan4108's picture
Update app.py
70e7cfd verified
raw
history blame
1.35 kB
from dotenv import load_dotenv
load_dotenv() # take environment variables from .env.
import streamlit as st
import os
from PIL import Image
import google.generativeai as genai
# Set the page configuration (must be the first Streamlit command)
st.set_page_config(page_title="Gemini Image Demo")
os.getenv("GOOGLE_API_KEY")
genai.configure(api_key=os.getenv("GOOGLE_API_KEY"))
## Function to load OpenAI model and get response
def get_gemini_response(input, image):
model = genai.GenerativeModel('gemini-1.5-flash')
if input != "":
response = model.generate_content([input, image])
else:
response = model.generate_content(image)
return response.text
## Initialize our Streamlit app
st.header("Food Analysis")
input1 =os.getenv("INPUT_PROMPT")
#input = st.text_input("Input Prompt: ", key="input", placeholder="Optional")
uploaded_file = st.file_uploader("Choose an image...", type=["jpg", "jpeg", "png"])
image = ""
if uploaded_file is not None:
image = Image.open(uploaded_file)
st.image(image, caption="Uploaded Image.", use_container_width=False, width=400)
submit = st.button("Check the Food Quality")
## If submit button is clicked
if submit:
with st.spinner("Please wait while assessing the food quality..."):
response = get_gemini_response(input1, image)
st.write(response)