HassanDataSci commited on
Commit
dee9805
·
verified ·
1 Parent(s): 54850f1

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +5 -11
app.py CHANGED
@@ -1,18 +1,12 @@
1
  import streamlit as st
2
  from transformers import pipeline
3
  from PIL import Image
4
- from langchain_community.chat_models import ChatGoogleGenerativeAI
5
- from langchain_community.llms import HuggingFacePipeline
6
  import os
7
 
8
  # Set up the Google API Key (add this as a secret in Hugging Face Spaces)
9
  os.environ["GOOGLE_API_KEY"] = st.secrets["GOOGLE_API_KEY"]
10
-
11
- # Initialize Google Gemini model
12
- llm = ChatGoogleGenerativeAI(
13
- model="gemini-1.5-pro",
14
- temperature=0
15
- )
16
 
17
  # Load the image classification pipeline
18
  @st.cache_resource
@@ -30,8 +24,8 @@ def get_ingredients_google(food_name):
30
  Generate a list of ingredients for the given food item using Google Gemini AI.
31
  """
32
  prompt = f"List the main ingredients typically used to prepare {food_name}:"
33
- response = llm.predict(prompt)
34
- return response.strip()
35
 
36
  # Streamlit app setup
37
  st.title("Food Image Recognition with Ingredients")
@@ -42,7 +36,7 @@ st.image("IR_IMAGE.png", caption="Food Recognition Model", use_column_width=True
42
  # Sidebar for model information
43
  st.sidebar.title("Model Information")
44
  st.sidebar.write("**Image Classification Model**: Shresthadev403/food-image-classification")
45
- st.sidebar.write("**LLM for Ingredients**: Google Gemini 1.5 Pro")
46
 
47
  # Upload image
48
  uploaded_file = st.file_uploader("Choose a food image...", type=["jpg", "png", "jpeg"])
 
1
  import streamlit as st
2
  from transformers import pipeline
3
  from PIL import Image
4
+ import google.generativeai as palm
 
5
  import os
6
 
7
  # Set up the Google API Key (add this as a secret in Hugging Face Spaces)
8
  os.environ["GOOGLE_API_KEY"] = st.secrets["GOOGLE_API_KEY"]
9
+ palm.configure(api_key=os.environ["GOOGLE_API_KEY"])
 
 
 
 
 
10
 
11
  # Load the image classification pipeline
12
  @st.cache_resource
 
24
  Generate a list of ingredients for the given food item using Google Gemini AI.
25
  """
26
  prompt = f"List the main ingredients typically used to prepare {food_name}:"
27
+ response = palm.chat(messages=[{"content": prompt}])
28
+ return response.last.strip() if response else "Could not generate ingredients."
29
 
30
  # Streamlit app setup
31
  st.title("Food Image Recognition with Ingredients")
 
36
  # Sidebar for model information
37
  st.sidebar.title("Model Information")
38
  st.sidebar.write("**Image Classification Model**: Shresthadev403/food-image-classification")
39
+ st.sidebar.write("**LLM for Ingredients**: Google Gemini")
40
 
41
  # Upload image
42
  uploaded_file = st.file_uploader("Choose a food image...", type=["jpg", "png", "jpeg"])