hiteshwar21 commited on
Commit
f387b0a
Β·
verified Β·
1 Parent(s): f2b4fa8

Upload diagnostic_script.py

Browse files
Files changed (1) hide show
  1. diagnostic_script.py +144 -0
diagnostic_script.py ADDED
@@ -0,0 +1,144 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #!/usr/bin/env python3
2
+ """Diagnostic script for HF Space deployment issues"""
3
+
4
+ import os
5
+ import sys
6
+ from pathlib import Path
7
+
8
+ def check_files():
9
+ """Check if all required files exist"""
10
+ print("=== File Check ===")
11
+
12
+ required_files = [
13
+ "config/settings.py",
14
+ "src/retrieval/semantic_retriever.py",
15
+ "src/generation/response_generator.py",
16
+ "data/vector_store/embeddings.npy",
17
+ "data/vector_store/faiss_index.bin",
18
+ "data/vector_store/chunks.pkl",
19
+ "data/vector_store/bm25.pkl",
20
+ "data/vector_store/relationships.pkl"
21
+ ]
22
+
23
+ for file_path in required_files:
24
+ if os.path.exists(file_path):
25
+ print(f"βœ… {file_path}")
26
+ else:
27
+ print(f"❌ {file_path} - MISSING")
28
+
29
+ def check_imports():
30
+ """Check if imports work"""
31
+ print("\n=== Import Check ===")
32
+
33
+ try:
34
+ from config.settings import config
35
+ print("βœ… Config imported")
36
+ print(f" - Embedding model: {config.EMBEDDING_MODEL}")
37
+ print(f" - Vector store path: {config.VECTOR_STORE_PATH}")
38
+ except Exception as e:
39
+ print(f"❌ Config import failed: {e}")
40
+ return
41
+
42
+ try:
43
+ from src.retrieval.semantic_retriever import SemanticRetriever
44
+ print("βœ… SemanticRetriever imported")
45
+ except Exception as e:
46
+ print(f"❌ SemanticRetriever import failed: {e}")
47
+
48
+ try:
49
+ from src.generation.response_generator import ResponseGenerator
50
+ print("βœ… ResponseGenerator imported")
51
+ except Exception as e:
52
+ print(f"❌ ResponseGenerator import failed: {e}")
53
+
54
+ try:
55
+ from sentence_transformers import SentenceTransformer
56
+ print("βœ… SentenceTransformers imported")
57
+ except Exception as e:
58
+ print(f"❌ SentenceTransformers import failed: {e}")
59
+
60
+ try:
61
+ import faiss
62
+ print("βœ… FAISS imported")
63
+ except Exception as e:
64
+ print(f"❌ FAISS import failed: {e}")
65
+
66
+ def check_vector_store():
67
+ """Check vector store files"""
68
+ print("\n=== Vector Store Check ===")
69
+
70
+ try:
71
+ from config.settings import config
72
+
73
+ # Check embeddings
74
+ import numpy as np
75
+ embeddings = np.load(os.path.join(config.VECTOR_STORE_PATH, "embeddings.npy"))
76
+ print(f"βœ… Embeddings loaded: {embeddings.shape}")
77
+
78
+ # Check FAISS
79
+ import faiss
80
+ faiss_index = faiss.read_index(os.path.join(config.VECTOR_STORE_PATH, "faiss_index.bin"))
81
+ print(f"βœ… FAISS index loaded: {faiss_index.ntotal} vectors")
82
+
83
+ # Check chunks
84
+ import pickle
85
+ with open(os.path.join(config.VECTOR_STORE_PATH, "chunks.pkl"), "rb") as f:
86
+ chunks = pickle.load(f)
87
+ print(f"βœ… Chunks loaded: {len(chunks)} chunks")
88
+
89
+ # Check BM25
90
+ with open(os.path.join(config.VECTOR_STORE_PATH, "bm25.pkl"), "rb") as f:
91
+ bm25 = pickle.load(f)
92
+ print(f"βœ… BM25 loaded")
93
+
94
+ except Exception as e:
95
+ print(f"❌ Vector store check failed: {e}")
96
+
97
+ def check_model_loading():
98
+ """Check if embedding model loads"""
99
+ print("\n=== Model Loading Check ===")
100
+
101
+ try:
102
+ from config.settings import config
103
+ from sentence_transformers import SentenceTransformer
104
+
105
+ print("Loading embedding model...")
106
+ model = SentenceTransformer(config.EMBEDDING_MODEL, device='cpu')
107
+ print("βœ… Embedding model loaded")
108
+
109
+ # Test encoding
110
+ test_embedding = model.encode(["test"], show_progress_bar=False)
111
+ print(f"βœ… Test encoding successful: shape {test_embedding.shape}")
112
+
113
+ except Exception as e:
114
+ print(f"❌ Model loading failed: {e}")
115
+
116
+ def check_api_keys():
117
+ """Check API keys"""
118
+ print("\n=== API Keys Check ===")
119
+
120
+ openrouter_key = os.getenv("OPENROUTER_API_KEY")
121
+ tavily_key = os.getenv("TAVILY_API_KEY")
122
+
123
+ if openrouter_key:
124
+ print("βœ… OPENROUTER_API_KEY found")
125
+ else:
126
+ print("❌ OPENROUTER_API_KEY missing")
127
+
128
+ if tavily_key:
129
+ print("βœ… TAVILY_API_KEY found")
130
+ else:
131
+ print("⚠️ TAVILY_API_KEY missing (optional)")
132
+
133
+ if __name__ == "__main__":
134
+ print("πŸ” MANIT RAG Chatbot Diagnostic")
135
+ print("=" * 50)
136
+
137
+ check_files()
138
+ check_imports()
139
+ check_vector_store()
140
+ check_model_loading()
141
+ check_api_keys()
142
+
143
+ print("\n" + "=" * 50)
144
+ print("Diagnostic complete!")