Spaces:
Sleeping
Sleeping
Update app.py
Browse files22 unmodified lines23242526262728293031333432333435363738394040414243444546474849504243444522 unmodified lines
pipe_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." 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 to extract only the list of ingredients # Post-process the response ingredients = 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 format if "," not in ingredients: # If the model didn't output a list, fallback to generic handling ingredients = "No ingredients found or response unclear." return ingredients except Exception as e: return f"Error generating ingredients: {e}" 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