Spaces:
Sleeping
Sleeping
Download check_structure.py from logesh28/hybrid-rag-ai-assistant: direct link, hf CLI and curl.
- Browser
- Download file 6.24 kB
-
https://huggingface.co/spaces/logesh28/hybrid-rag-ai-assistant/resolve/main/check_structure.py
- Command line
-
hf download hf://spaces/logesh28/hybrid-rag-ai-assistant/check_structure.py
-
curl -L -o check_structure.py https://huggingface.co/spaces/logesh28/hybrid-rag-ai-assistant/resolve/main/check_structure.py
6.24 kB
| """ | |
| Loki AI - Structure Checker & Auto-Fixer | |
| Run this from your LOKI_AI root folder | |
| """ | |
| import os | |
| import shutil | |
| import sys | |
| ROOT = os.getcwd() | |
| print("=" * 60) | |
| print("π Loki AI - Structure Check") | |
| print(f"π Root: {ROOT}") | |
| print("=" * 60) | |
| issues = [] | |
| fixes = [] | |
| # === Check 1: Required folders === | |
| required_folders = ["app", "data"] | |
| for folder in required_folders: | |
| path = os.path.join(ROOT, folder) | |
| if os.path.exists(path): | |
| print(f"β /{folder} folder exists") | |
| else: | |
| print(f"β /{folder} folder MISSING") | |
| issues.append(f"Missing folder: {folder}") | |
| # === Check 2: templates location === | |
| templates_in_app = os.path.exists(os.path.join(ROOT, "app", "templates")) | |
| templates_in_root = os.path.exists(os.path.join(ROOT, "templates")) | |
| if templates_in_app: | |
| print(f"β οΈ templates/ is inside app/ β should be in root") | |
| fixes.append("MOVE_TEMPLATES") | |
| elif templates_in_root: | |
| print(f"β templates/ is in root") | |
| else: | |
| print(f"β templates/ folder MISSING") | |
| issues.append("Missing templates folder") | |
| # === Check 3: Core app files === | |
| core_files = ["app/main.py", "app/rag_engine.py", "app/build_index.py"] | |
| for f in core_files: | |
| path = os.path.join(ROOT, f) | |
| if os.path.exists(path): | |
| print(f"β {f} exists") | |
| else: | |
| print(f"β {f} MISSING") | |
| issues.append(f"Missing: {f}") | |
| # === Check 4: .env file === | |
| env_path = os.path.join(ROOT, ".env") | |
| if os.path.exists(env_path): | |
| with open(env_path) as f: | |
| content = f.read() | |
| if "GROQ_API_KEY" in content and "your_groq_api_key" not in content: | |
| print(f"β .env exists with GROQ_API_KEY") | |
| else: | |
| print(f"β οΈ .env exists but GROQ_API_KEY not set properly") | |
| issues.append("GROQ_API_KEY not set in .env") | |
| else: | |
| print(f"β .env file MISSING") | |
| issues.append("Missing .env file") | |
| # === Check 5: FAISS index === | |
| faiss_root = os.path.join(ROOT, "faiss_index.idx") | |
| faiss_app = os.path.join(ROOT, "app", "faiss_index.idx") | |
| chunks_root = os.path.join(ROOT, "chunks.pkl") | |
| chunks_app = os.path.join(ROOT, "app", "chunks.pkl") | |
| if os.path.exists(faiss_root): | |
| print(f"β faiss_index.idx in root") | |
| else: | |
| print(f"β faiss_index.idx MISSING from root") | |
| issues.append("faiss_index.idx not in root") | |
| if os.path.exists(faiss_app): | |
| print(f"β οΈ faiss_index.idx duplicate in app/ β will remove") | |
| fixes.append("REMOVE_DUPLICATE_FAISS") | |
| if os.path.exists(chunks_root): | |
| print(f"β chunks.pkl in root") | |
| else: | |
| print(f"β chunks.pkl MISSING from root") | |
| issues.append("chunks.pkl not in root") | |
| if os.path.exists(chunks_app): | |
| print(f"β οΈ chunks.pkl duplicate in app/ β will remove") | |
| fixes.append("REMOVE_DUPLICATE_CHUNKS") | |
| # === Check 6: Junk files === | |
| junk_files = [ | |
| "app/templates/python.py", | |
| "app/templates/test.py", | |
| "chunks.npy", | |
| "app/chunks.npy" | |
| ] | |
| for jf in junk_files: | |
| if os.path.exists(os.path.join(ROOT, jf)): | |
| print(f"β οΈ Junk file found: {jf} β will remove") | |
| fixes.append(f"REMOVE_JUNK:{jf}") | |
| # === Check 7: Old model folder === | |
| model_folder = os.path.join(ROOT, "model") | |
| if os.path.exists(model_folder): | |
| size_mb = sum( | |
| os.path.getsize(os.path.join(dp, f)) | |
| for dp, dn, filenames in os.walk(model_folder) | |
| for f in filenames | |
| ) / (1024 * 1024) | |
| print(f"β οΈ Old model/ folder found ({size_mb:.0f} MB) β safe to delete manually") | |
| issues.append(f"Old FLAN-T5 model folder ({size_mb:.0f} MB) - delete manually to free space") | |
| # === Check 8: __init__.py === | |
| init_path = os.path.join(ROOT, "app", "__init__.py") | |
| if os.path.exists(init_path): | |
| print(f"β app/__init__.py exists") | |
| else: | |
| print(f"β οΈ app/__init__.py missing β will create") | |
| fixes.append("CREATE_INIT") | |
| # === Check 9: requirements.txt === | |
| req_path = os.path.join(ROOT, "requirements.txt") | |
| if os.path.exists(req_path): | |
| with open(req_path) as f: | |
| reqs = f.read() | |
| if "groq" in reqs: | |
| print(f"β requirements.txt has groq") | |
| else: | |
| print(f"β οΈ requirements.txt missing 'groq' package") | |
| issues.append("requirements.txt needs groq package") | |
| else: | |
| print(f"β requirements.txt MISSING") | |
| issues.append("Missing requirements.txt") | |
| # === Summary === | |
| print("\n" + "=" * 60) | |
| print(f"π SUMMARY: {len(issues)} issues, {len(fixes)} auto-fixes available") | |
| print("=" * 60) | |
| if issues: | |
| print("\nπ΄ Issues Found:") | |
| for i, issue in enumerate(issues, 1): | |
| print(f" {i}. {issue}") | |
| if fixes: | |
| print(f"\nπ§ Auto-fixes ready ({len(fixes)} items)") | |
| confirm = input("\nβ Apply all fixes now? (y/n): ").strip().lower() | |
| if confirm == 'y': | |
| print("\nπ§ Applying fixes...") | |
| for fix in fixes: | |
| if fix == "MOVE_TEMPLATES": | |
| src = os.path.join(ROOT, "app", "templates") | |
| dst = os.path.join(ROOT, "templates") | |
| shutil.move(src, dst) | |
| print(f" β Moved templates/ to root") | |
| elif fix == "REMOVE_DUPLICATE_FAISS": | |
| os.remove(os.path.join(ROOT, "app", "faiss_index.idx")) | |
| print(f" β Removed duplicate app/faiss_index.idx") | |
| elif fix == "REMOVE_DUPLICATE_CHUNKS": | |
| os.remove(os.path.join(ROOT, "app", "chunks.pkl")) | |
| print(f" β Removed duplicate app/chunks.pkl") | |
| elif fix == "CREATE_INIT": | |
| with open(os.path.join(ROOT, "app", "__init__.py"), "w") as f: | |
| f.write("") | |
| print(f" β Created app/__init__.py") | |
| elif fix.startswith("REMOVE_JUNK:"): | |
| junk = fix.split(":", 1)[1] | |
| os.remove(os.path.join(ROOT, junk)) | |
| print(f" β Removed {junk}") | |
| print("\nβ All fixes applied!") | |
| print("\nπ Next steps:") | |
| print(" 1. Delete model/ folder manually (saves disk space)") | |
| print(" 2. Set GROQ_API_KEY in .env file") | |
| print(" 3. pip install -r requirements.txt") | |
| print(" 4. uvicorn app.main:app --reload") | |
| else: | |
| print("βοΈ Fixes skipped. Run again and press 'y' to apply.") | |
| else: | |
| print("\nπ Structure looks clean!") | |