goldrode commited on
Commit
58dc866
·
verified ·
1 Parent(s): 6af8198

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +11 -2
app.py CHANGED
@@ -1,4 +1,5 @@
1
  import json
 
2
  import os
3
  import faiss
4
  from sentence_transformers import SentenceTransformer
@@ -30,9 +31,17 @@ def generate_advice(extracted_data):
30
  try:
31
  recommendations = []
32
  for item in extracted_data:
33
- # Query FAISS for the closest match
34
  query = f"{item['Component']} {item['Status']}"
 
 
35
  query_embedding = embedding_model.encode([query])
 
 
 
 
 
 
36
  _, idx = index.search(query_embedding, 1)
37
  best_match = kb[idx[0][0]]
38
 
@@ -75,7 +84,7 @@ def generate_advice(extracted_data):
75
  return recommendations
76
 
77
  except Exception as e:
78
- # Ensure Gradio JSON output is always valid
79
  return [{"error": str(e)}]
80
 
81
  # Gradio app with LLM integration
 
1
  import json
2
+ import numpy as np
3
  import os
4
  import faiss
5
  from sentence_transformers import SentenceTransformer
 
31
  try:
32
  recommendations = []
33
  for item in extracted_data:
34
+ # Prepare the query string
35
  query = f"{item['Component']} {item['Status']}"
36
+
37
+ # Generate query embedding (ensure it's a valid numpy array)
38
  query_embedding = embedding_model.encode([query])
39
+ query_embedding = np.array(query_embedding).astype('float32') # Explicit cast
40
+
41
+ if query_embedding.shape != (1, index.d): # FAISS index shape check
42
+ raise ValueError("Query embedding shape mismatch. Check input to the embedding model.")
43
+
44
+ # Search the FAISS index for the closest match
45
  _, idx = index.search(query_embedding, 1)
46
  best_match = kb[idx[0][0]]
47
 
 
84
  return recommendations
85
 
86
  except Exception as e:
87
+ # Return structured error message
88
  return [{"error": str(e)}]
89
 
90
  # Gradio app with LLM integration