Spaces:
Sleeping
Sleeping
| import logging | |
| import os | |
| from dotenv import load_dotenv | |
| # Initialize logging configuration | |
| logging.basicConfig(level=logging.INFO) | |
| logger = logging.getLogger(__name__) | |
| # Load environment variables from the .env file | |
| load_dotenv() | |
| # Retrieve API keys from environment variables | |
| openai_api_key = os.getenv("OPENAI_API_KEY") | |
| # Validate the presence of API keys | |
| if not openai_api_key: | |
| # Log an error message and raise an exception if any API key is missing | |
| logger.error("API keys are not set properly.") | |
| raise ValueError("API keys for OpenAI must be set in the .env file.") | |
| else: | |
| # Log a success message if both API keys are present | |
| logger.info("API keys loaded successfully.") | |