Spaces:
Sleeping
Sleeping
Update app.py
Browse files22 unmodified lines2324252627282930313233343536373839404142434445464748495051525322 unmodified linespipe_bloom = load_bloom_pipeline()# Function to generate ingredients using BLOOMdef get_ingredients_bloom(food_name):"""Generate a list of ingredients for the given food item using BLOOM.Returns a clean, comma-separated list of ingredients."""prompt = (f"List only the main ingredients typically used to prepare {food_name}. ""Provide the ingredients as a simple, comma-separated list such as: ingredient1, ingredient2, ingredient3.")try:response = pipe_bloom(prompt, max_length=50, num_return_sequences=1)generated_text = response[0]["generated_text"].strip()# Post-process to extract only the list of ingredientsingredients = generated_text.split(":")[-1].strip() # Handle cases like "Ingredients: ..."ingredients = ingredients.replace(".", "").strip() # Remove periods and extra spaces# Ensure the response is a proper list formatif "," not in ingredients: # If the model didn't output a list, fallback to generic handlingingredients = "No ingredients found or response unclear."return ingredientsexcept Exception as e:return f"Error generating ingredients: {e}"# Streamlit app setupst.title("Food Image Recognition with Ingredients")22 unmodified lines232425262728293031323334353637383940414243444522 unmodified linespipe_bloom = load_bloom_pipeline()def get_ingredients_bloom(food_name):"""Generate a list of ingredients for the given food item using BLOOM.Returns a clean, comma-separated list of ingredients."""prompt = (f"Generate a list of the main ingredients used to prepare {food_name}. ""Respond only with a concise, comma-separated list of ingredients, without any additional text, explanations, or placeholders. ""For example, if the food is pizza, respond with 'cheese, tomato sauce, bread, olive oil, basil'.")try:response = pipe_bloom(prompt, max_length=50, num_return_sequences=1)generated_text = response[0]["generated_text"].strip()# Post-process the responseingredients = generated_text.split(":")[-1].strip() # Handle cases like "Ingredients: ..."ingredients = ingredients.replace(".", "").strip() # Remove periods and return f"Error generating ingredients: {e}"# Streamlit app setupst.title("Food Image Recognition with Ingredients")
app.py+5-13