Futuresony commited on
Commit
5977d71
·
verified ·
1 Parent(s): 4c839c8

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +27 -3
app.py CHANGED
@@ -163,24 +163,48 @@ def load_llm_model(model_id, hf_token):
163
 
164
  # --- Load all assets on startup ---
165
  print("Loading assets...")
166
- # Removed nlp = load_spacy_model()
167
  embedder = load_sentence_transformer()
 
 
168
  data, descriptions, _ = load_google_sheet_data(SHEET_ID, GOOGLE_SERVICE_ACCOUNT_KEY_BASE64)
 
 
169
 
170
  if embedder and descriptions:
171
  print("Encoding Google Sheet descriptions...")
172
  try:
173
  embeddings = embedder.encode(descriptions, convert_to_tensor=True)
174
  print("Encoding complete.")
 
175
  except Exception as e:
176
  print(f"Error during embedding: {e}")
177
- embeddings = torch.tensor([])
178
  else:
179
  print("Skipping embedding due to missing embedder or descriptions.")
180
- embeddings = torch.tensor([])
 
181
 
182
  model, tokenizer = load_llm_model(model_id, HF_TOKEN)
 
 
183
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
184
  # Check if essential components loaded (Removed nlp from this check)
185
  if not model or not tokenizer or not embedder:
186
  print("\nERROR: Essential components failed to load. The application may not function correctly.")
 
163
 
164
  # --- Load all assets on startup ---
165
  print("Loading assets...")
166
+ # Removed nlp = load_spacy_model() # Keep this line commented out if you removed spaCy
167
  embedder = load_sentence_transformer()
168
+ print(f"Embedder loaded: {embedder is not None}") # Add this print
169
+
170
  data, descriptions, _ = load_google_sheet_data(SHEET_ID, GOOGLE_SERVICE_ACCOUNT_KEY_BASE64)
171
+ print(f"Google Sheet data loaded: {len(data)} rows") # Add this print
172
+ print(f"Google Sheet descriptions loaded: {len(descriptions)} items") # Add this print
173
 
174
  if embedder and descriptions:
175
  print("Encoding Google Sheet descriptions...")
176
  try:
177
  embeddings = embedder.encode(descriptions, convert_to_tensor=True)
178
  print("Encoding complete.")
179
+ print(f"Embeddings shape: {embeddings.shape}") # Add this print
180
  except Exception as e:
181
  print(f"Error during embedding: {e}")
182
+ embeddings = torch.tensor([]) # Ensure embeddings is an empty tensor on error
183
  else:
184
  print("Skipping embedding due to missing embedder or descriptions.")
185
+ embeddings = torch.tensor([]) # Ensure embeddings is an empty tensor when skipped
186
+ print(f"Embeddings tensor after skip: {embeddings.shape}") # Should print torch.Size([])
187
 
188
  model, tokenizer = load_llm_model(model_id, HF_TOKEN)
189
+ print(f"LLM Model loaded: {model is not None}") # Add this print
190
+ print(f"LLM Tokenizer loaded: {tokenizer is not None}") # Add this print
191
 
192
+ # Check if essential components loaded
193
+ # This block provides a summary if anything failed during loading
194
+ if not model or not tokenizer or not embedder or embeddings is None or embeddings.numel() == 0 or not data:
195
+ print("\nERROR: Essential components failed to load. The application may not function correctly.")
196
+ if not model: print("- LLM Model failed to load.")
197
+ if not tokenizer: print("- LLM Tokenizer failed to load.")
198
+ if not embedder: print("- Sentence Embedder failed to load.")
199
+ # Check if embeddings is not None before accessing numel()
200
+ if embeddings is None or embeddings.numel() == 0: print("- Embeddings are empty or None.")
201
+ if not data: print("- Google Sheet Data is empty.")
202
+ # Descriptions being empty is implicitly covered by data being empty in this context
203
+ # if not descriptions: print("- Google Sheet Descriptions are empty.")
204
+ # Removed spaCy error message
205
+ # Continue, but the main inference function will need checks (already handled by the check at start of respond)
206
+ else:
207
+ print("\nAll essential components loaded successfully.") # Add this print
208
  # Check if essential components loaded (Removed nlp from this check)
209
  if not model or not tokenizer or not embedder:
210
  print("\nERROR: Essential components failed to load. The application may not function correctly.")