i am gettting this error when i am trying to generate the recipe only using the input image
"
No ingredients found. Please upload an image with clear ingredients or manually enter ingredients.
"
please use only the gemini-1.5-flash model to extract the ingredients names from the image...as flash model can analyze the images too
"
import os
import json
import base64
import re
from flask import Flask, render_template, request, jsonify
import google.generativeai as genai
import PIL.Image
from werkzeug.utils import secure_filename

app = Flask(__name__)
app.secret_key = 'your_secret_key_here'  # Replace with a real secret key

# Configure Gemini API
GEMINI_API_KEY = ''  # Replace with your actual API key
genai.configure(api_key=GEMINI_API_KEY)
model = genai.GenerativeModel("gemini-1.5-flash")

def generate_recipes_from_ingredients(ingredients, previous_recipes=None):
    """Generate recipe names based on ingredients, avoiding previously generated recipes."""
    try:
        exclusion_clause = f" Do not include these recipes: {', '.join(previous_recipes)}" if previous_recipes else ""
        
        prompt = f"""Generate a list of 5 unique recipe names that can be made using the following ingredients: {ingredients}. 
        Ensure the recipes are creative and different from any previously generated recipes.{exclusion_clause}
        Respond in the following strict JSON format:
        {{
            "recipes": [
                "Recipe Name 1",
                "Recipe Name 2",
                "Recipe Name 3",
                "Recipe Name 4",
                "Recipe Name 5"
            ]
        }}"""
        
        response = model.generate_content(
            prompt,
            generation_config=genai.types.GenerationConfig(
                temperature=0.8,
                max_output_tokens=300
            )
        )
        
        json_match = re.search(r'\{.*\}', response.text, re.DOTALL)
        if json_match:
            return json.loads(json_match.group(0))['recipes']
        return []
    except Exception as e:
        print(f"Error generating recipes: {e}")
        return []

def generate_recipe_details(recipe_name, ingredients):
    """Generate detailed recipe information."""
    try:
        prompt = f"""Generate detailed recipe information for {recipe_name} using ingredients: {ingredients}. 
        Provide a response in the following strict JSON format:
        {{
            "name": "Recipe Name",
            "ingredients": ["Ingredient 1", "Ingredient 2"],
            "instructions": ["Step 1", "Step 2", "Step 3"],
            "who_can_eat": ["Vegetarians", "Vegans"],
            "who_should_avoid": ["Gluten Intolerant", "Dairy Allergies"],
            "additional_info": "Any extra notes about the recipe"
        }}"""
        
        response = model.generate_content(
            prompt,
            generation_config=genai.types.GenerationConfig(
                temperature=0.5,
                max_output_tokens=1000
            )
        )
        
        json_match = re.search(r'\{.*\}', response.text, re.DOTALL)
        if json_match:
            return json.loads(json_match.group(0))
        return None
    except Exception as e:
        print(f"Error generating recipe details: {e}")
        return None

def extract_ingredients_from_image(image):
    """Extract ingredients from image using Gemini's direct image analysis."""
    try:
        prompt = """Identify all food ingredients in this image. 
        List raw and prepared ingredients you can see. 
        Provide a comma-separated list of ingredients."""
        
        response = model.generate_content(
            [prompt, image],
            generation_config=genai.types.GenerationConfig(
                temperature=0.5,
                max_output_tokens=200
            )
        )
        
        ingredients_text = response.text.strip()
        
        # Remove any non-ingredient text, keep only ingredients
        ingredients = [ing.strip() for ing in ingredients_text.split(',') if ing.strip()]
        
        return ', '.join(ingredients) if ingredients else ''
    except Exception as e:
        print(f"Error extracting ingredients from image: {e}")
        return ''

@app.route('/', methods=['GET'])
def index():
    return render_template('index.html')

@app.route('/generate_recipes', methods=['POST'])
def generate_recipes():
    ingredients = request.form.get('ingredients', '')
    previous_recipes = request.form.getlist('previous_recipes[]')
    image = request.files.get('image')
    
    if image and image.filename:
        img = PIL.Image.open(image)
        image_ingredients = extract_ingredients_from_image(img)
        ingredients = image_ingredients if image_ingredients else ingredients
    
    if not ingredients:
        return jsonify({"error": "No ingredients detected or provided"}), 400
    
    recipes = generate_recipes_from_ingredients(ingredients, previous_recipes)
    return jsonify(recipes)

@app.route('/get_recipe_details', methods=['POST'])
def get_recipe_details():
    recipe_name = request.form.get('recipe_name')
    ingredients = request.form.get('ingredients')
    image = request.files.get('image')
    
    if image and image.filename:
        img = PIL.Image.open(image)
        image_ingredients = extract_ingredients_from_image(img)
        ingredients = image_ingredients if image_ingredients else ingredients
    
    if not recipe_name or not ingredients:
        return jsonify({"error": "No ingredients found. Please upload an image with clear ingredients or manually enter ingredients."}), 400
    
    recipe_details = generate_recipe_details(recipe_name, ingredients)
    return jsonify(recipe_details)

if __name__ == '__main__':
    app.run(debug=True)
"