CoolFace
Apppublic

Neerajkadari/Context-Aware_Conversational_Intelligence_System

sourceHugging Faceupdated 5mo agoView on Hugging Face
0likes
config.py156 linesDownload Raw Back to root
1"""2Global Configuration for the Conversational Intelligence System.3Centralizes all paths, hyperparameters, and model settings.4"""5 6import os7from pathlib import Path8 9# ──────────────────────────────────────────────────────────────10# PATHS11# ──────────────────────────────────────────────────────────────12BASE_DIR = Path(__file__).parent.resolve()13DATA_DIR = BASE_DIR / "data"14MODEL_DIR = BASE_DIR / "models"15REPORT_DIR = BASE_DIR / "reports"16VECTOR_DB_DIR = BASE_DIR / "vector_store"17LOG_DIR = BASE_DIR / "logs"18 19# Create directories20for d in [DATA_DIR, MODEL_DIR, REPORT_DIR, VECTOR_DB_DIR, LOG_DIR]:21    d.mkdir(parents=True, exist_ok=True)22 23# ──────────────────────────────────────────────────────────────24# DATASET25# ──────────────────────────────────────────────────────────────26DATASET_NAME = "ag_news"27NUM_CLASSES = 428CLASS_NAMES = ["World", "Sports", "Business", "Sci/Tech"]29MAX_SAMPLES_TRAIN = 200        # Small sample for fast automatic demo30MAX_SAMPLES_TEST = 5031 32# ──────────────────────────────────────────────────────────────33# MODEL CONFIGURATIONS34# ──────────────────────────────────────────────────────────────35MODELS = {36    "bert": {37        "name": "bert-base-uncased",38        "architecture": "Bidirectional Transformer Encoder",39        "description": "Reads text in both directions simultaneously for strong contextual understanding",40        "max_length": 128,41        "batch_size": 16,42        "learning_rate": 2e-5,43        "epochs": 3,44        "weight_decay": 0.01,45    },46    "gpt2": {47        "name": "gpt2",48        "architecture": "Autoregressive Transformer Decoder",49        "description": "Token-by-token text generation with causal attention mechanism",50        "max_length": 128,51        "batch_size": 8,52        "learning_rate": 5e-5,53        "epochs": 1,54        "weight_decay": 0.01,55    },56    "llama": {57        "name": "TinyLlama/TinyLlama-1.1B-Chat-v1.0",58        "architecture": "Decoder-based Large Language Model",59        "description": "Efficient transformer architecture with strong reasoning ability",60        "max_length": 128,61        "batch_size": 4,62        "learning_rate": 2e-5,63        "epochs": 1,64        "weight_decay": 0.01,65        "use_lora": True,66        "lora_r": 8,67        "lora_alpha": 16,68        "lora_dropout": 0.1,69    },70    "mistral": {71        "name": "mistralai/Mistral-7B-v0.1",72        "architecture": "Transformer with Sliding Window Attention",73        "description": "Efficient long-context processing with fast inference",74        "max_length": 128,75        "batch_size": 2,76        "learning_rate": 2e-5,77        "epochs": 1,78        "weight_decay": 0.01,79        "use_lora": True,80        "lora_r": 8,81        "lora_alpha": 16,82        "lora_dropout": 0.1,83        "local_training": False,84    },85    "xlnet": {86        "name": "xlnet-base-cased",87        "architecture": "Permutation-based Autoregressive Transformer",88        "description": "Combines autoregressive and bidirectional modeling for improved contextual understanding",89        "max_length": 128,90        "batch_size": 16,91        "learning_rate": 2e-5,92        "epochs": 1,93        "weight_decay": 0.01,94    },95}96 97# ──────────────────────────────────────────────────────────────98# EMBEDDING / RAG99# ──────────────────────────────────────────────────────────────100EMBEDDING_MODEL = "all-MiniLM-L6-v2"101CHROMA_COLLECTION = "project_knowledge"102CHUNK_SIZE = 500103CHUNK_OVERLAP = 50104TOP_K_RESULTS = 5105 106# ──────────────────────────────────────────────────────────────107# CONVERSATIONAL AI108# ──────────────────────────────────────────────────────────────109GROQ_MODEL = "llama-3.1-8b-instant"110MAX_RESPONSE_TOKENS = 1000111TEMPERATURE = 0.3112 113# ──────────────────────────────────────────────────────────────114# SERVER115# ──────────────────────────────────────────────────────────────116HOST = os.environ.get("HOST", "0.0.0.0")117PORT = int(os.environ.get("PORT", "8509"))118DEBUG = True119# Model Download from HF Hub120import shutil121import logging122 123logger = logging.getLogger(__name__)124 125def download_models_if_needed():126    """Download models from Neerajkadari/my_project_models if not present locally."""127    from huggingface_hub import snapshot_download128    129    models_needed = ["bert", "gpt2", "llama", "xlnet"]130    any_missing = any(131        not (MODEL_DIR / m).exists() 132        for m in models_needed133    )134    if any_missing:135        logger.info("Downloading models from Neerajkadari/my_project_models...")136        local_path = snapshot_download(137            repo_id="Neerajkadari/my_project_models",138            repo_type="model",139            local_dir=str(BASE_DIR / "downloaded_models"),140            force_download=True141        )142        # Move models into expected location143        src = Path(local_path) / "models"144        for model_name in models_needed:145            src_model = src / model_name146            dst_model = MODEL_DIR / model_name147            if src_model.exists() and not dst_model.exists():148                shutil.copytree(str(src_model), str(dst_model))149                logger.info(f"Model '{model_name}' placed at {dst_model}")150            elif dst_model.exists():151                logger.info(f"Model '{model_name}' already exists at {dst_model}")152        logger.info("Model download complete!")153 154# Auto-download models on import155if not any((MODEL_DIR / m).exists() for m in ["bert", "gpt2", "llama", "xlnet"]):156    download_models_if_needed()