"""Configuration settings for the API""" import os from pathlib import Path from dotenv import load_dotenv import logging # Configure logging logger = logging.getLogger(__name__) # Load environment variables from .env file load_dotenv() # Get project root directory API_DIR = Path(__file__).parent PROJECT_ROOT = API_DIR.parent # Hugging Face configuration HUGGINGFACE_API_KEY = os.getenv("HUGGINGFACE_API_KEY", "") HUGGINGFACE_STANCE_MODEL_ID = os.getenv("HUGGINGFACE_STANCE_MODEL_ID") HUGGINGFACE_LABEL_MODEL_ID = os.getenv("HUGGINGFACE_LABEL_MODEL_ID") HUGGINGFACE_STT_MODEL_ID = os.getenv("HUGGINGFACE_STT_MODEL_ID") # Use Hugging Face model ID instead of local path STANCE_MODEL_ID = HUGGINGFACE_STANCE_MODEL_ID LABEL_MODEL_ID = HUGGINGFACE_LABEL_MODEL_ID # API configuration API_TITLE = "NLP Project API" API_DESCRIPTION = "API for various NLP models including stance detection and more" API_VERSION = "1.0.0" # Server configuration HOST = os.getenv("HOST", "0.0.0.0") # Use 0.0.0.0 for Docker/Spaces PORT = int(os.getenv("PORT", "7860")) # Default 7860 for Hugging Face Spaces RELOAD = os.getenv("RELOAD", "False").lower() == "true" # Set to False in production # CORS configuration CORS_ORIGINS = ["*"] # In production, specify exact origins CORS_CREDENTIALS = True CORS_METHODS = ["*"] CORS_HEADERS = ["*"] # Free model configurations STT_MODEL_ID = "openai/whisper-small" # Free Whisper model for STT CHATBOT_MODEL_ID = "microsoft/DialoGPT-medium" # Free chatbot model TTS_USE_GTTS = True # Use gTTS (Google Text-to-Speech) free tier # Audio settings ALLOWED_AUDIO_TYPES = { "audio/wav", "audio/x-wav", "audio/mpeg", "audio/mp3", "audio/mp4", "audio/m4a" } MAX_TEXT_LENGTH = 500 MIN_TEXT_LENGTH = 1 MAX_AUDIO_SIZE = 10 * 1024 * 1024 # 10MB # Validate configuration def validate_config(): """Validate that we can use free models""" logger.info("✓ Using free models for STT, TTS, and Chatbot") return True validate_config()