reachify-ai-service / scripts /download_embedding_model.py
amitbhatt6075's picture
Complete fresh start - FINAL UPLOAD
0914e96
# 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()