import streamlit as st from transformers import pipeline from PIL import Image import os # Load the image classification pipeline @st.cache_resource def load_image_classification_pipeline(): """ Load the image classification pipeline using a pretrained model. """ return pipeline("image-classification", model="Shresthadev403/food-image-classification") pipe_classification = load_image_classification_pipeline() # Load the BLOOM model for ingredient generation @st.cache_resource def load_bloom_pipeline(): """ Load the BLOOM model for ingredient generation. """ return pipeline("text-generation", model="bigscience/bloom-1b7") pipe_bloom = load_bloom_pipeline() # Function to generate ingredients using BLOOM 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 response