|
|
import logging |
|
|
import sys |
|
|
import traceback |
|
|
import os |
|
|
|
|
|
|
|
|
logging.basicConfig(level=logging.INFO, format='%(asctime)s - %(levelname)s - %(message)s') |
|
|
|
|
|
def run_step(step_func, step_name): |
|
|
"""Runs a step and logs its success or failure.""" |
|
|
logging.info(f"--- Starting step: {step_name} ---") |
|
|
try: |
|
|
step_func() |
|
|
logging.info(f"--- Finished step: {step_name} successfully ---") |
|
|
return True |
|
|
except Exception as e: |
|
|
logging.error(f"--- Step failed: {step_name} ---") |
|
|
logging.error(f"Error: {e}") |
|
|
|
|
|
logging.error(traceback.format_exc()) |
|
|
return False |
|
|
|
|
|
def main(): |
|
|
"""Runs the daily update sequence.""" |
|
|
|
|
|
|
|
|
script_dir = os.path.dirname(os.path.abspath(__file__)) |
|
|
if script_dir not in sys.path: |
|
|
sys.path.append(script_dir) |
|
|
logging.info(f"Added {script_dir} to sys.path for local imports.") |
|
|
|
|
|
|
|
|
logging.info("=== Starting Daily Model Update Process ===") |
|
|
|
|
|
all_steps_succeeded = True |
|
|
|
|
|
|
|
|
try: |
|
|
|
|
|
from huggingface_model_descriptions import main as fetch_models_main |
|
|
if not run_step(fetch_models_main, "Fetch Hugging Face Models"): |
|
|
all_steps_succeeded = False |
|
|
|
|
|
|
|
|
logging.error("Stopping update process for this cycle due to failure in fetching models.") |
|
|
return |
|
|
except ImportError: |
|
|
logging.error("Failed to import huggingface_model_descriptions.py. Ensure it's in the same directory or Python path.") |
|
|
all_steps_succeeded = False |
|
|
return |
|
|
except Exception as e: |
|
|
logging.error(f"Unexpected error setting up model fetching step: {e}") |
|
|
logging.error(traceback.format_exc()) |
|
|
all_steps_succeeded = False |
|
|
return |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if all_steps_succeeded: |
|
|
try: |
|
|
from add_model_explanations import main as add_explanations_main |
|
|
|
|
|
if not os.getenv("GEMINI_API_KEY"): |
|
|
logging.warning("GEMINI_API_KEY environment variable not set. Explanation step will fail or do nothing.") |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if not run_step(add_explanations_main, "Generate Model Explanations (Gemini)"): |
|
|
all_steps_succeeded = False |
|
|
|
|
|
logging.warning("Explanation generation failed. Index will be built with potentially missing explanations.") |
|
|
|
|
|
|
|
|
except ImportError: |
|
|
logging.error("Failed to import add_model_explanations.py. Ensure it's in the same directory or Python path.") |
|
|
all_steps_succeeded = False |
|
|
|
|
|
return |
|
|
except Exception as e: |
|
|
logging.error(f"Unexpected error setting up explanation generation step: {e}") |
|
|
logging.error(traceback.format_exc()) |
|
|
all_steps_succeeded = False |
|
|
return |
|
|
|
|
|
|
|
|
|
|
|
if 'fetch_models_main' in locals() or 'fetch_models_main' in globals(): |
|
|
try: |
|
|
from build_index import main as build_index_main |
|
|
if not run_step(build_index_main, "Build Search Index (FAISS)"): |
|
|
all_steps_succeeded = False |
|
|
logging.error("Index building failed. The search index may be outdated or corrupted.") |
|
|
|
|
|
return |
|
|
except ImportError: |
|
|
logging.error("Failed to import build_index.py. Ensure it's in the same directory or Python path.") |
|
|
all_steps_succeeded = False |
|
|
return |
|
|
except Exception as e: |
|
|
logging.error(f"Unexpected error setting up index building step: {e}") |
|
|
logging.error(traceback.format_exc()) |
|
|
all_steps_succeeded = False |
|
|
return |
|
|
|
|
|
|
|
|
logging.info("===========================================") |
|
|
if all_steps_succeeded: |
|
|
logging.info("=== Daily Model Update Process Completed Successfully ===") |
|
|
else: |
|
|
logging.error("=== Daily Model Update Process Completed with Errors ===") |
|
|
|
|
|
if __name__ == "__main__": |
|
|
main() |