File size: 1,992 Bytes
9db766f 95cb26e 9db766f 492be8b 3a33610 f28285b 73d4f3c 9db766f 70a2026 f8a4eeb 9db766f 9a6ab0c 95cb26e 9a6ab0c 918acab 95cb26e 918acab |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 |
"""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() |