File size: 973 Bytes
a6bbf63
0c746c9
a6bbf63
 
0c746c9
 
a6bbf63
 
 
 
0c746c9
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
from transformers import RobertaTokenizerFast, RobertaForSequenceClassification
from utils.commons import HUGGINGFACE_MODEL_PATH, MODEL_SAVE_PATH, setup_logging
import os

logger = setup_logging("model_ingestion.log")

class ModelIngestor:
    @staticmethod
    def download_model():
        """Download and save the model"""
        try:
            if not os.path.exists(MODEL_SAVE_PATH):
                os.makedirs(MODEL_SAVE_PATH)
                logger.info(f"Created directory: {MODEL_SAVE_PATH}")

            logger.info("Downloading tokenizer and model...")
            RobertaTokenizerFast.from_pretrained(HUGGINGFACE_MODEL_PATH).save_pretrained(MODEL_SAVE_PATH)
            RobertaForSequenceClassification.from_pretrained(HUGGINGFACE_MODEL_PATH).save_pretrained(MODEL_SAVE_PATH)
            logger.info(f"Model and tokenizer saved to {MODEL_SAVE_PATH}")
        except Exception as e:
            logger.error(f"Error downloading model: {e}")
            raise