Upload backend/verify_setup.py with huggingface_hub
Browse files- backend/verify_setup.py +111 -0
backend/verify_setup.py
ADDED
|
@@ -0,0 +1,111 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""
|
| 2 |
+
Verification script for Sentinel-AI semantic search feature.
|
| 3 |
+
Run this to verify all components are correctly configured.
|
| 4 |
+
"""
|
| 5 |
+
|
| 6 |
+
import sys
|
| 7 |
+
from pathlib import Path
|
| 8 |
+
|
| 9 |
+
def check_file(path: str, description: str) -> bool:
|
| 10 |
+
"""Check if a file exists."""
|
| 11 |
+
p = Path(path)
|
| 12 |
+
if p.exists():
|
| 13 |
+
print(f" β
{description}: {path}")
|
| 14 |
+
return True
|
| 15 |
+
else:
|
| 16 |
+
print(f" β {description} NOT FOUND: {path}")
|
| 17 |
+
return False
|
| 18 |
+
|
| 19 |
+
def check_env_var(var_name: str, description: str) -> bool:
|
| 20 |
+
"""Check if an environment variable is set."""
|
| 21 |
+
import os
|
| 22 |
+
value = os.getenv(var_name)
|
| 23 |
+
if value:
|
| 24 |
+
# Mask API keys for security
|
| 25 |
+
if "KEY" in var_name or "SECRET" in var_name:
|
| 26 |
+
display = value[:10] + "..." if len(value) > 10 else "***"
|
| 27 |
+
else:
|
| 28 |
+
display = value
|
| 29 |
+
print(f" β
{description}: {display}")
|
| 30 |
+
return True
|
| 31 |
+
else:
|
| 32 |
+
print(f" β {description} NOT SET")
|
| 33 |
+
return False
|
| 34 |
+
|
| 35 |
+
def main():
|
| 36 |
+
print("=" * 70)
|
| 37 |
+
print("SENTINEL-AI SEMANTIC SEARCH VERIFICATION")
|
| 38 |
+
print("=" * 70)
|
| 39 |
+
|
| 40 |
+
all_checks_passed = True
|
| 41 |
+
|
| 42 |
+
# Check backend files
|
| 43 |
+
print("\nπ Backend Files:")
|
| 44 |
+
all_checks_passed &= check_file("api/routes/search.py", "Search router")
|
| 45 |
+
all_checks_passed &= check_file("core/gemini_agent.py", "Gemini agent")
|
| 46 |
+
all_checks_passed &= check_file("core/faiss_store.py", "FAISS store")
|
| 47 |
+
all_checks_passed &= check_file("api/schemas.py", "API schemas")
|
| 48 |
+
all_checks_passed &= check_file("main.py", "Main entry point")
|
| 49 |
+
|
| 50 |
+
# Check index artifacts
|
| 51 |
+
print("\nπΎ Index Artifacts:")
|
| 52 |
+
all_checks_passed &= check_file("index_artifacts/celeb_index.faiss", "FAISS index")
|
| 53 |
+
all_checks_passed &= check_file("index_artifacts/metadata.json", "Metadata file")
|
| 54 |
+
|
| 55 |
+
# Check environment
|
| 56 |
+
print("\nπ§ Environment Configuration:")
|
| 57 |
+
from dotenv import load_dotenv
|
| 58 |
+
load_dotenv("../.env")
|
| 59 |
+
|
| 60 |
+
all_checks_passed &= check_env_var("GOOGLE_API_KEY", "Gemini API key")
|
| 61 |
+
all_checks_passed &= check_env_var("GEMINI_MODEL", "Gemini model")
|
| 62 |
+
|
| 63 |
+
# Test imports
|
| 64 |
+
print("\nπ¦ Python Imports:")
|
| 65 |
+
try:
|
| 66 |
+
from api.routes.search import router
|
| 67 |
+
print(" β
Search router imports successfully")
|
| 68 |
+
except Exception as e:
|
| 69 |
+
print(f" β Search router import failed: {e}")
|
| 70 |
+
all_checks_passed = False
|
| 71 |
+
|
| 72 |
+
try:
|
| 73 |
+
from core.gemini_agent import extract_attributes_from_query
|
| 74 |
+
print(" β
Gemini agent imports successfully")
|
| 75 |
+
except Exception as e:
|
| 76 |
+
print(f" β Gemini agent import failed: {e}")
|
| 77 |
+
all_checks_passed = False
|
| 78 |
+
|
| 79 |
+
try:
|
| 80 |
+
from core.faiss_store import search_by_attributes
|
| 81 |
+
print(" β
FAISS store imports successfully")
|
| 82 |
+
except Exception as e:
|
| 83 |
+
print(f" β FAISS store import failed: {e}")
|
| 84 |
+
all_checks_passed = False
|
| 85 |
+
|
| 86 |
+
# Check cascadeflow
|
| 87 |
+
print("\nπ‘οΈ Cascadeflow:")
|
| 88 |
+
try:
|
| 89 |
+
import cascadeflow
|
| 90 |
+
print(f" β
Cascadeflow version: {cascadeflow.__version__}")
|
| 91 |
+
except Exception as e:
|
| 92 |
+
print(f" β Cascadeflow not available: {e}")
|
| 93 |
+
all_checks_passed = False
|
| 94 |
+
|
| 95 |
+
# Final summary
|
| 96 |
+
print("\n" + "=" * 70)
|
| 97 |
+
if all_checks_passed:
|
| 98 |
+
print("β
ALL CHECKS PASSED - System ready for semantic search!")
|
| 99 |
+
print("\nStart the backend with:")
|
| 100 |
+
print(" python -m uvicorn main:app --host 0.0.0.0 --port 8000 --reload")
|
| 101 |
+
print("\nThen test the endpoint:")
|
| 102 |
+
print(' curl -X POST http://localhost:8000/api/v1/semantic-search \\')
|
| 103 |
+
print(' -H "Content-Type: application/json" \\')
|
| 104 |
+
print(' -d \'{"query": "smiling woman with blond hair", "top_k": 5}\'')
|
| 105 |
+
else:
|
| 106 |
+
print("β SOME CHECKS FAILED - Review errors above")
|
| 107 |
+
sys.exit(1)
|
| 108 |
+
print("=" * 70)
|
| 109 |
+
|
| 110 |
+
if __name__ == "__main__":
|
| 111 |
+
main()
|