File size: 1,448 Bytes
0914e96
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
# ai-service/scripts/download_embedding_model.py

from sentence_transformers import SentenceTransformer
import os

# --- Configuration ---
# Hum is popular model ko use karenge. Yeh chota aur effective hai.
MODEL_NAME = 'sentence-transformers/all-MiniLM-L6-v2' 

# Path jahan model save hoga. Yeh aapke main.py ke `EMBEDDING_MODEL_PATH` se match karna chahiye.
SAVE_PATH = os.path.join(os.path.dirname(os.path.dirname(__file__)), 'embedding_model')

# --- Main Logic ---
def download_model():
    """
    Downloads the sentence-transformer model from Hugging Face and saves it locally.
    """
    print(f"--- πŸš€ Starting download for model: {MODEL_NAME} ---")
    
    # Check if the path already exists
    if os.path.exists(SAVE_PATH) and len(os.listdir(SAVE_PATH)) > 0:
        print(f"--- βœ… Model directory already exists and is not empty. Skipping download. ---")
        print(f"    Path: {SAVE_PATH}")
        return

    print(f"    Saving model to: {SAVE_PATH}")
    
    try:
        # Model download aur save karein
        model = SentenceTransformer(MODEL_NAME)
        model.save(SAVE_PATH)
        print(f"--- βœ… Model downloaded and saved successfully! ---")
    except Exception as e:
        print(f"--- 🚨 ERROR: Failed to download or save the model. ---")
        print(f"    Error details: {e}")
        print(f"    Please check your internet connection and try again.")

if __name__ == "__main__":
    download_model()