i am getting this error "Missing recipe name or ingredients" when i am uploading the image ...as we are not entering the ingredients name na when uploading the image...add a prompt to extract the ingredients in the provided image by the user...
"
import os
import json
import base64
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:
        # If previous recipes are provided, explicitly exclude them
        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
            )
        )
        
        # Extract JSON from response using regex
        import re
        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
            )
        )
        
        # Extract JSON from response using regex
        import re
        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 analyze_ingredients_from_image(image):
    """Analyze ingredients from an uploaded image."""
    try:
        prompt = """Identify the ingredients in this image. 
        Respond in the following strict JSON format:
        {
            "ingredients": ["Ingredient 1", "Ingredient 2", "Ingredient 3"]
        }"""
        
        response = model.generate_content(
            [prompt, image],
            generation_config=genai.types.GenerationConfig(
                temperature=0.5,
                max_output_tokens=300
            )
        )
        
        # Extract JSON from response using regex
        import re
        json_match = re.search(r'\{.*\}', response.text, re.DOTALL)
        if json_match:
            return ', '.join(json.loads(json_match.group(0))['ingredients'])
        return ''
    except Exception as e:
        print(f"Error analyzing image ingredients: {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:
        # Process image
        img = PIL.Image.open(image)
        ingredients = analyze_ingredients_from_image(img)
    
    if not ingredients:
        return jsonify({"error": "No ingredients 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')
    
    if not recipe_name or not ingredients:
        return jsonify({"error": "Missing recipe name or ingredients"}), 400
    
    recipe_details = generate_recipe_details(recipe_name, ingredients)
    return jsonify(recipe_details)

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