HassanDataSci commited on
Commit
a34ab64
·
verified ·
1 Parent(s): 7013cc6

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +5 -13
app.py CHANGED
@@ -23,31 +23,23 @@ def load_bloom_pipeline():
23
 
24
  pipe_bloom = load_bloom_pipeline()
25
 
26
- # Function to generate ingredients using BLOOM
27
  def get_ingredients_bloom(food_name):
28
  """
29
  Generate a list of ingredients for the given food item using BLOOM.
30
  Returns a clean, comma-separated list of ingredients.
31
  """
32
  prompt = (
33
- f"List only the main ingredients typically used to prepare {food_name}. "
34
- "Provide the ingredients as a simple, comma-separated list such as: ingredient1, ingredient2, ingredient3."
 
35
  )
36
  try:
37
  response = pipe_bloom(prompt, max_length=50, num_return_sequences=1)
38
  generated_text = response[0]["generated_text"].strip()
39
 
40
- # Post-process to extract only the list of ingredients
41
  ingredients = generated_text.split(":")[-1].strip() # Handle cases like "Ingredients: ..."
42
- ingredients = ingredients.replace(".", "").strip() # Remove periods and extra spaces
43
-
44
- # Ensure the response is a proper list format
45
- if "," not in ingredients: # If the model didn't output a list, fallback to generic handling
46
- ingredients = "No ingredients found or response unclear."
47
-
48
- return ingredients
49
- except Exception as e:
50
- return f"Error generating ingredients: {e}"
51
 
52
  # Streamlit app setup
53
  st.title("Food Image Recognition with Ingredients")
 
23
 
24
  pipe_bloom = load_bloom_pipeline()
25
 
 
26
  def get_ingredients_bloom(food_name):
27
  """
28
  Generate a list of ingredients for the given food item using BLOOM.
29
  Returns a clean, comma-separated list of ingredients.
30
  """
31
  prompt = (
32
+ f"Generate a list of the main ingredients used to prepare {food_name}. "
33
+ "Respond only with a concise, comma-separated list of ingredients, without any additional text, explanations, or placeholders. "
34
+ "For example, if the food is pizza, respond with 'cheese, tomato sauce, bread, olive oil, basil'."
35
  )
36
  try:
37
  response = pipe_bloom(prompt, max_length=50, num_return_sequences=1)
38
  generated_text = response[0]["generated_text"].strip()
39
 
40
+ # Post-process the response
41
  ingredients = generated_text.split(":")[-1].strip() # Handle cases like "Ingredients: ..."
42
+ ingredients = ingredients.replace(".", "").strip() # Remove periods and return f"Error generating ingredients: {e}"
 
 
 
 
 
 
 
 
43
 
44
  # Streamlit app setup
45
  st.title("Food Image Recognition with Ingredients")