What is the best way to handle this, I'll include script 3_create.py and all information needed for a successful api text to image woukd it be best to create a script before the 3_create.py that takes all the info from my json file and writes a script in the structure they want it or what? import json
import os
import requests
from datetime import datetime
import subprocess
from dotenv import load_dotenv
import sys
import traceback

def main():
    # Get the directory of the current script
    script_dir = os.path.dirname(os.path.abspath(__file__))

    # Load environment variables from the .env file in the script's directory
    dotenv_path = os.path.join(script_dir, '.env')
    if not os.path.isfile(dotenv_path):
        print(f"Error: '.env' file not found in {script_dir}.")
        sys.exit(1)
    load_dotenv(dotenv_path)

    # Generate the image
    image_path = generate_image(script_dir)
    if image_path:
        print("Running logo overlay script...")
        if overlay_logo(image_path, script_dir):
            print("Image generation and logo overlay process completed successfully.")
        else:
            print("Image generated successfully, but logo overlay failed.")
    else:
        print("Image generation failed. Logo overlay not attempted.")

def generate_image(script_dir):
    # Path to new_prompt.json
    prompt_file_path = os.path.join(script_dir, 'data', 'new_prompt.json')
    if not os.path.isfile(prompt_file_path):
        print(f"Error: '{prompt_file_path}' file not found.")
        return None

    # Load the prompt
    try:
        with open(prompt_file_path, 'r') as f:
            prompt_data = json.load(f)
    except json.JSONDecodeError as e:
        print(f"Error: Invalid JSON in '{prompt_file_path}': {e}")
        return None

    # Hugging Face API setup
    API_URL = os.getenv('API_URL')
    API_KEY = os.getenv('HF_API_KEY')

    if not API_URL:
        print("Error: 'API_URL' not set in .env file.")
        return None
    if not API_KEY:
        print("Error: 'HF_API_KEY' not set in .env file.")
        return None

    print(f"Using API_URL: {API_URL}")
    headers = {"Authorization": f"Bearer {API_KEY}"}

    try:
        response = requests.post(API_URL, headers=headers, json=prompt_data, timeout=60)
        response.raise_for_status()

        # Verify response content is an image
        content_type = response.headers.get('Content-Type', '')
        if 'image' not in content_type:
            print(f"Error: Unexpected content type in response: {content_type}")
            return None

        # Save the image
        output_dir = os.path.join(script_dir, 'output', 'ads')
        os.makedirs(output_dir, exist_ok=True)
        timestamp = datetime.now().strftime("%Y%m%d_%H%M%S")
        image_path = os.path.join(output_dir, f'ad_base_{timestamp}.png')

        with open(image_path, 'wb') as f:
            f.write(response.content)

        print(f"Image generated successfully: {image_path}")
        return image_path

    except requests.exceptions.RequestException as e:
        print(f"Error making request to Hugging Face API: {e}")
        return None
    except Exception as e:
        print(f"Unexpected error generating image: {e}")
        traceback.print_exc()
        return None

def overlay_logo(image_path, script_dir):
    try:
        logo_script_path = os.path.join(script_dir, 'scripts', '4_logo.py')
        if not os.path.isfile(logo_script_path):
            print(f"Error: '{logo_script_path}' script not found.")
            return False

        # Run the logo overlay script with the image path as an argument
        result = subprocess.run(['python', logo_script_path, image_path],
                                check=True, capture_output=True, text=True)
        print("Logo overlay completed successfully.")
        print(result.stdout)
        return True
    except subprocess.CalledProcessError as e:
        print(f"Error running logo overlay script:\n{e.stderr}")
        return False
    except Exception as e:
        print(f"Unexpected error during logo overlay: {e}")
        traceback.print_exc()
        return False

if __name__ == "__main__":
    main()
import requests

# Replace with your actual Hugging Face API token
API_TOKEN = "hf_your_api_token_here"

API_URL = "https://api-inference.huggingface.co/models/ZB-Tech/Text-to-Image"
headers = {
    "Authorization": f"Bearer {API_TOKEN}",
    "Content-Type": "application/json"
}

def query(payload):
    response = requests.post(API_URL, headers=headers, json=payload)
    # Check if the response was successful
    if response.status_code == 200:
        return response.content
    else:
        # Print out the error details
        print(f"Error: {response.status_code} - {response.text}")
        response.raise_for_status()

prompt = "A digital art piece of a futuristic city with flying cars at sunset."

payload = {
    "inputs": prompt
}

try:
    image_data = query(payload)
    # Save the image data to a file
    with open("output.png", "wb") as f:
        f.write(image_data)
    print("Image generated successfully and saved as output.png.")
except requests.exceptions.HTTPError as e:
    print(f"An HTTP error occurred: {e}")
except Exception as e:
    print(f"An error occurred: {e}")

Will use me dotenv in /root/mm/final/scripts/.env

HF_API_KEY=RealApiIsInMyDotenv
API_URL = "https://api-inference.huggingface.co/models/ZB-Tech/Text-to-Image"

                                            company_info.json
{
  "setup_date": "2024-10-05T13:09:33.085027",
  "last_modified": "2024-10-05T13:09:33.085041",
  "company_name": "Game Changer Gaming",
  "slogan": "WIN,WIN WIN!",
  "description": "It is an online social gaming provider, we offer video slots to customers to play fromvthe comfort of home",
  "preferred_styles": [
    "Bold",
    "Vintage",
    "Modern",
    "Colorful",
    "Whimsical",
    "Futuristic"
  ],
  "preferred_colors": [
    "Red",
    "Blue",
    "Green",
    "Black",
    "White",
    "Purple",
    "Orange",
    "Pink"
  ],
  "contact_info": {
    "phone": "(903) 576-2529",
    "text": ""
  },