class_docstr: This integration seamlessly combines MindsDB and Leonardo AI to create a powerful
  AI-driven solution for creative content generation.
  
  Content Generation with Leonardo AI: Harness the power of advanced generative
  models for creative content production. From realistic images to artistic text, Leonardo
  AI opens up new possibilities for content creators.
class_docstr_tok: ["This","integration","seamlessly","combines","MindsDB","and","Leonardo","AI","to","create","a","powerful","AI-driven","solution","for","creative","content","generation",".","Content","Generation","with","Leonardo","AI",":","Harness","the","power","of","advanced","generative","models","for","creative","content","production",".","From","realistic","images","to","artistic","text",",","Leonardo","AI","opens","up","new","possibilities","for","content","creators","."]
docstr: Generates pictures based on the prompts and returns URLs with few variations.
  
  Request Flow:
      - POST request with a prompt is sent
      - `generation_id` is created for the request
      - POST request will take couple of seconds to generate the picture, till then the process will be kept busy with a simple math calculation.
      - New GET request with the `generation_id` will fetch the generated pictures as URLs
docstr_tok: ["Generates","pictures","based","on","the","prompts","and","returns","URLs","with","few","variations",".","Request","Flow",":","-","POST","request","with","a","prompt","is","sent","-","`","generation_id","`","is","created","for","the","request","-","POST","request","will","take","couple","of","seconds","to","generate","the","picture",",","till","then","the","process","will","be","kept","busy","with","a","simple","math","calculation",".","-","New","GET","request","with","the","`","generation_id","`","will","fetch","the","generated","pictures","as","URLs"]
code: def predict_answer(self, prompts, **kwargs):
      """
      Generates pictures based on the prompts and returns URLs with few variations.
  
      Request Flow:
          - POST request with a prompt is sent
          - `generation_id` is created for the request
          - POST request will take couple of seconds to generate the picture, till then the process will be kept busy with a simple math calculation.
          - New GET request with the `generation_id` will fetch the generated pictures as URLs
      """
      args = self.model_storage.json_get("args")
      tmp_args = args["using"]
      height = tmp_args.get("height", 512)
      width = tmp_args.get("width", 512)
      api_key = self._get_leonardo_api_key(
          args, self.engine_storage
      )  # fetch API key
      generation_id = ""
  
      # Endpoint URL
      generation_url = (
          "https://cloud.leonardo.ai/api/rest/v1/generations"
      )
  
      post_headers = {
          "accept": "application/json",
          "content-type": "application/json",
          "authorization": f"Bearer {api_key}",
      }
  
      get_headers = {
          "accept": "application/json",
          "authorization": f"Bearer {api_key}",
      }
  
      # payload
      generation_payload = {
          "height": height,
          "modelId": args["using"]["model"],
          "prompt": f"{prompts}",
          "width": width,
      }
  
      # Make a POST request to generate the image
      response_generation = requests.post(
          generation_url, json=generation_payload, headers=post_headers
      )
      generation_data = response_generation.json()
  
      # Wait for 15 seconds
  
      time.sleep(15)
  
      # extract generationID from the response
      generation_id = generation_data["sdGenerationJob"]["generationId"]
  
      # ENDPOINT GET URL
      retrieve_url = f"https://cloud.leonardo.ai/api/rest/v1/generations/{generation_id}"
  
      # GET request to retrieve image URLs
      response_retrieve = requests.get(
          retrieve_url, headers=get_headers
      )
      retrieve_data = response_retrieve.json()
  
      # extract URLs from the response
      generated_images = retrieve_data["generations_by_pk"][
          "generated_images"
      ]
      image_urls = [image["url"] for image in generated_images]
  
      url_dicts = []
  
      for url in image_urls:
          url_dicts.append({"url": url})
  
      img_urls = pd.DataFrame(url_dicts, columns=["url"])
      return img_urls
  
file_path: mindsdb/mindsdb/integrations/handlers/leonardoai_handler/leonardo_ai_handler.py
imports: import os
  import requests
  import time
  from typing import Dict, Optional
  from mindsdb.integrations.libs.llm_utils import get_completed_prompts
  import pandas
  from mindsdb.integrations.libs.base import BaseMLEngine
  from mindsdb.utilities import log
  from mindsdb.interfaces.storage.model_fs import HandlerStorage
  from mindsdb.utilities.config import Config
label_desc: Use image node_id 6 for calling the LeonardoAIHandler obj's underlying member method code with example usage: obj.predict_answer(prompts) and returns: img_urls