Spaces:
Sleeping
Sleeping
Update app.py
Browse files12345678910111213141516171811 unmodified lines30313233343536374 unmodified lines42434445464748import streamlit as stfrom transformers import pipelinefrom PIL import Imagefrom langchain_community.chat_models import ChatGoogleGenerativeAIfrom langchain_community.llms import HuggingFacePipelineimport os# Set up the Google API Key (add this as a secret in Hugging Face Spaces)os.environ["GOOGLE_API_KEY"] = st.secrets["GOOGLE_API_KEY"]# Initialize Google Gemini modelllm = ChatGoogleGenerativeAI(model="gemini-1.5-pro",temperature=0)# Load the image classification pipeline@st.cache_resource11 unmodified linesGenerate a list of ingredients for the given food item using Google Gemini AI."""prompt = f"List the main ingredients typically used to prepare {food_name}:"response = llm.predict(prompt)return response.strip()# Streamlit app setupst.title("Food Image Recognition with Ingredients")4 unmodified lines# Sidebar for model informationst.sidebar.title("Model Information")st.sidebar.write("**Image Classification Model**: Shresthadev403/food-image-classification")st.sidebar.write("**LLM for Ingredients**: Google Gemini 1.5 Pro")# Upload imageuploaded_file = st.file_uploader("Choose a food image...", type=["jpg", "png", "jpeg"])12345678910111211 unmodified lines24252627282930314 unmodified lines36373839404142import streamlit as stfrom transformers import pipelinefrom PIL import Imageimport google.generativeai as palmimport os# Set up the Google API Key (add this as a secret in Hugging Face Spaces)os.environ["GOOGLE_API_KEY"] = st.secrets["GOOGLE_API_KEY"]palm.configure(api_key=os.environ["GOOGLE_API_KEY"])# Load the image classification pipeline@st.cache_resource11 unmodified linesGenerate a list of ingredients for the given food item using Google Gemini AI."""prompt = f"List the main ingredients typically used to prepare {food_name}:"response = palm.chat(messages=[{"content": prompt}])return response.last.strip() if response else "Could not generate ingredients."# Streamlit app setupst.title("Food Image Recognition with Ingredients")4 unmodified lines# Sidebar for model informationst.sidebar.title("Model Information")st.sidebar.write("**Image Classification Model**: Shresthadev403/food-image-classification")st.sidebar.write("**LLM for Ingredients**: Google Gemini")# Upload imageuploaded_file = st.file_uploader("Choose a food image...", type=["jpg", "png", "jpeg"])
app.py+5-11