HassanDataSci commited on
Commit
e73380c
·
verified ·
1 Parent(s): fb4422e

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +7 -12
app.py CHANGED
@@ -1,11 +1,8 @@
1
  import streamlit as st
2
- from transformers import pipeline, AutoTokenizer, AutoModelForCausalLM
3
  from PIL import Image
4
  import os
5
 
6
- # Hugging Face token login (add this as a secret in Hugging Face Spaces)
7
- os.environ["HF_TOKEN"] = st.secrets["HF_AUTH_TOKEN"]
8
-
9
  # Load the image classification pipeline
10
  @st.cache_resource
11
  def load_image_classification_pipeline():
@@ -16,22 +13,20 @@ def load_image_classification_pipeline():
16
 
17
  pipe_classification = load_image_classification_pipeline()
18
 
19
- # Load the Llama model for ingredient generation
20
  @st.cache_resource
21
  def load_llama_pipeline():
22
  """
23
- Load the Llama model for ingredient generation.
24
  """
25
- tokenizer = AutoTokenizer.from_pretrained("meta-llama/Llama-3.2-3B-Instruct", use_auth_token=os.environ["HF_TOKEN"])
26
- model = AutoModelForCausalLM.from_pretrained("meta-llama/Llama-3.2-3B-Instruct", use_auth_token=os.environ["HF_TOKEN"])
27
- return pipeline("text-generation", model=model, tokenizer=tokenizer)
28
 
29
  pipe_llama = load_llama_pipeline()
30
 
31
- # Function to generate ingredients using the Llama model
32
  def get_ingredients_llama(food_name):
33
  """
34
- Generate a list of ingredients for the given food item using the Llama model.
35
  """
36
  prompt = f"List the main ingredients typically used to prepare {food_name}."
37
  try:
@@ -49,7 +44,7 @@ st.image("IR_IMAGE.png", caption="Food Recognition Model", use_column_width=True
49
  # Sidebar for model information
50
  st.sidebar.title("Model Information")
51
  st.sidebar.write("**Image Classification Model**: Shresthadev403/food-image-classification")
52
- st.sidebar.write("**LLM for Ingredients**: meta-llama/Llama-3.2-3B-Instruct")
53
 
54
  # Upload image
55
  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 os
5
 
 
 
 
6
  # Load the image classification pipeline
7
  @st.cache_resource
8
  def load_image_classification_pipeline():
 
13
 
14
  pipe_classification = load_image_classification_pipeline()
15
 
16
+ # Load the GPT-Neo model for ingredient generation
17
  @st.cache_resource
18
  def load_llama_pipeline():
19
  """
20
+ Load the GPT-Neo model for ingredient generation.
21
  """
22
+ return pipeline("text-generation", model="EleutherAI/gpt-neo-1.3B")
 
 
23
 
24
  pipe_llama = load_llama_pipeline()
25
 
26
+ # Function to generate ingredients using GPT-Neo
27
  def get_ingredients_llama(food_name):
28
  """
29
+ Generate a list of ingredients for the given food item using GPT-Neo.
30
  """
31
  prompt = f"List the main ingredients typically used to prepare {food_name}."
32
  try:
 
44
  # Sidebar for model information
45
  st.sidebar.title("Model Information")
46
  st.sidebar.write("**Image Classification Model**: Shresthadev403/food-image-classification")
47
+ st.sidebar.write("**LLM for Ingredients**: EleutherAI/gpt-neo-1.3B")
48
 
49
  # Upload image
50
  uploaded_file = st.file_uploader("Choose a food image...", type=["jpg", "png", "jpeg"])