StillWorking's picture
Upload backend/verify_setup.py with huggingface_hub
3ac937f verified
Raw History Blame Contribute Delete
3.84 kB
"""
Verification script for Sentinel-AI semantic search feature.
Run this to verify all components are correctly configured.
"""
import sys
from pathlib import Path
def check_file(path: str, description: str) -> bool:
"""Check if a file exists."""
p = Path(path)
if p.exists():
print(f" βœ… {description}: {path}")
return True
else:
print(f" ❌ {description} NOT FOUND: {path}")
return False
def check_env_var(var_name: str, description: str) -> bool:
"""Check if an environment variable is set."""
import os
value = os.getenv(var_name)
if value:
# Mask API keys for security
if "KEY" in var_name or "SECRET" in var_name:
display = value[:10] + "..." if len(value) > 10 else "***"
else:
display = value
print(f" βœ… {description}: {display}")
return True
else:
print(f" ❌ {description} NOT SET")
return False
def main():
print("=" * 70)
print("SENTINEL-AI SEMANTIC SEARCH VERIFICATION")
print("=" * 70)
all_checks_passed = True
# Check backend files
print("\nπŸ“ Backend Files:")
all_checks_passed &= check_file("api/routes/search.py", "Search router")
all_checks_passed &= check_file("core/gemini_agent.py", "Gemini agent")
all_checks_passed &= check_file("core/faiss_store.py", "FAISS store")
all_checks_passed &= check_file("api/schemas.py", "API schemas")
all_checks_passed &= check_file("main.py", "Main entry point")
# Check index artifacts
print("\nπŸ’Ύ Index Artifacts:")
all_checks_passed &= check_file("index_artifacts/celeb_index.faiss", "FAISS index")
all_checks_passed &= check_file("index_artifacts/metadata.json", "Metadata file")
# Check environment
print("\nπŸ”§ Environment Configuration:")
from dotenv import load_dotenv
load_dotenv("../.env")
all_checks_passed &= check_env_var("GOOGLE_API_KEY", "Gemini API key")
all_checks_passed &= check_env_var("GEMINI_MODEL", "Gemini model")
# Test imports
print("\nπŸ“¦ Python Imports:")
try:
from api.routes.search import router
print(" βœ… Search router imports successfully")
except Exception as e:
print(f" ❌ Search router import failed: {e}")
all_checks_passed = False
try:
from core.gemini_agent import extract_attributes_from_query
print(" βœ… Gemini agent imports successfully")
except Exception as e:
print(f" ❌ Gemini agent import failed: {e}")
all_checks_passed = False
try:
from core.faiss_store import search_by_attributes
print(" βœ… FAISS store imports successfully")
except Exception as e:
print(f" ❌ FAISS store import failed: {e}")
all_checks_passed = False
# Check cascadeflow
print("\nπŸ›‘οΈ Cascadeflow:")
try:
import cascadeflow
print(f" βœ… Cascadeflow version: {cascadeflow.__version__}")
except Exception as e:
print(f" ❌ Cascadeflow not available: {e}")
all_checks_passed = False
# Final summary
print("\n" + "=" * 70)
if all_checks_passed:
print("βœ… ALL CHECKS PASSED - System ready for semantic search!")
print("\nStart the backend with:")
print(" python -m uvicorn main:app --host 0.0.0.0 --port 8000 --reload")
print("\nThen test the endpoint:")
print(' curl -X POST http://localhost:8000/api/v1/semantic-search \\')
print(' -H "Content-Type: application/json" \\')
print(' -d \'{"query": "smiling woman with blond hair", "top_k": 5}\'')
else:
print("❌ SOME CHECKS FAILED - Review errors above")
sys.exit(1)
print("=" * 70)
if __name__ == "__main__":
main()