Spaces:
Runtime error
Runtime error
| """ | |
| Diagnostic script for HuggingFace Spaces deployment | |
| Run this to check what's happening in the Space | |
| """ | |
| import os | |
| import sys | |
| from pathlib import Path | |
| print("=" * 60) | |
| print("π HuggingFace Space Diagnostic Report") | |
| print("=" * 60) | |
| # Check Python version | |
| print(f"\nπ Python Version: {sys.version}") | |
| # Check current directory | |
| print(f"\nπ Current Directory: {os.getcwd()}") | |
| print(f"π Directory Contents:") | |
| for item in sorted(os.listdir(".")): | |
| print(f" - {item}") | |
| # Check if data directory exists | |
| data_path = Path("data") | |
| if data_path.exists(): | |
| print(f"\nβ Data directory found") | |
| print(f"π Data directory contents:") | |
| for item in sorted(data_path.rglob("*")): | |
| if item.is_file(): | |
| print(f" - {item.relative_to(data_path)} ({item.stat().st_size} bytes)") | |
| else: | |
| print(f"\nβ Data directory NOT found!") | |
| # Check if src directory exists | |
| src_path = Path("src") | |
| if src_path.exists(): | |
| print(f"\nβ Src directory found") | |
| print(f"π Src directory structure:") | |
| for item in sorted(src_path.rglob("*.py")): | |
| print(f" - {item.relative_to(src_path)}") | |
| else: | |
| print(f"\nβ Src directory NOT found!") | |
| # Check environment variables | |
| print(f"\nπ Environment Variables:") | |
| required_vars = [ | |
| "AZURE_OPENAI_API_KEY", | |
| "AZURE_OPENAI_ENDPOINT", | |
| "AZURE_OPENAI_DEPLOYMENT_NAME", | |
| "AZURE_OPENAI_EMBEDDING_DEPLOYMENT_NAME", | |
| "AZURE_OPENAI_API_VERSION", | |
| ] | |
| for var in required_vars: | |
| value = os.getenv(var) | |
| if value: | |
| # Mask sensitive values | |
| if "KEY" in var: | |
| display = f"{value[:10]}...{value[-5:]}" if len(value) > 15 else "***" | |
| elif "ENDPOINT" in var: | |
| display = f"{value[:40]}..." if len(value) > 40 else value | |
| else: | |
| display = value | |
| print(f" β {var}: {display}") | |
| else: | |
| print(f" β {var}: NOT SET") | |
| # Try importing dependencies | |
| print(f"\nπ¦ Checking Dependencies:") | |
| dependencies = [ | |
| "gradio", | |
| "langchain", | |
| "langchain_openai", | |
| "langchain_community", | |
| "faiss", | |
| "rank_bm25", | |
| "dotenv", | |
| ] | |
| for dep in dependencies: | |
| try: | |
| if dep == "faiss": | |
| import faiss | |
| elif dep == "dotenv": | |
| import dotenv | |
| else: | |
| __import__(dep) | |
| print(f" β {dep}") | |
| except ImportError as e: | |
| print(f" β {dep}: {e}") | |
| # Try importing project modules | |
| print(f"\nπ§ Checking Project Modules:") | |
| sys.path.insert(0, str(Path(__file__).parent / "src")) | |
| try: | |
| from setup_retrieval import setup_retrieval_system | |
| print(f" β setup_retrieval") | |
| except Exception as e: | |
| print(f" β setup_retrieval: {e}") | |
| try: | |
| from rag.chain import UPBRAGChain | |
| print(f" β UPBRAGChain") | |
| except Exception as e: | |
| print(f" β UPBRAGChain: {e}") | |
| try: | |
| from metadata.metadata_manager import MetadataManager | |
| print(f" β MetadataManager") | |
| except Exception as e: | |
| print(f" β MetadataManager: {e}") | |
| # Try minimal RAG initialization | |
| print(f"\nπ Attempting RAG Initialization:") | |
| try: | |
| from setup_retrieval import setup_retrieval_system | |
| print(" - Loading documents...") | |
| retriever, vectorstore_manager, chunks = setup_retrieval_system() | |
| print(f" β Success! Loaded {len(chunks)} chunks") | |
| except Exception as e: | |
| import traceback | |
| print(f" β Failed:") | |
| print(f"\n{traceback.format_exc()}") | |
| print("\n" + "=" * 60) | |
| print("β Diagnostic Complete") | |
| print("=" * 60) | |