abrah926 commited on
Commit
4e2c9cd
Β·
verified Β·
1 Parent(s): 14a2007

running faiss script

Browse files
Files changed (1) hide show
  1. app.py +29 -0
app.py CHANGED
@@ -2,6 +2,8 @@ import gradio as gr
2
  from huggingface_hub import InferenceClient
3
  from datasets import load_dataset
4
  import time
 
 
5
 
6
  def log(message):
7
  print(f"βœ… {message}")
@@ -88,6 +90,33 @@ demo = gr.Interface(
88
  )
89
 
90
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
91
  # Launch Gradio app
92
  if __name__ == "__main__":
93
  demo.launch()
 
2
  from huggingface_hub import InferenceClient
3
  from datasets import load_dataset
4
  import time
5
+ import faiss
6
+ import numpy as np
7
 
8
  def log(message):
9
  print(f"βœ… {message}")
 
90
  )
91
 
92
 
93
+ # βœ… Function to check FAISS index
94
+ def check_faiss():
95
+ index_path = "my_embeddings" # Adjust if needed
96
+
97
+ try:
98
+ index = faiss.read_index(index_path)
99
+ num_vectors = index.ntotal
100
+ dim = index.d
101
+
102
+ if num_vectors > 0:
103
+ sample_vectors = index.reconstruct_n(0, min(5, num_vectors)) # Get first 5 embeddings
104
+ return f"πŸ“Š FAISS index contains {num_vectors} vectors.\nβœ… Embedding dimension: {dim}\n🧐 Sample: {sample_vectors[:2]} ..."
105
+ else:
106
+ return "⚠️ No embeddings found in FAISS index!"
107
+
108
+ except Exception as e:
109
+ return f"❌ ERROR: Failed to load FAISS index - {e}"
110
+
111
+ # βœ… Add a Gradio button to trigger FAISS check
112
+ with gr.Blocks() as demo:
113
+ gr.Markdown("### πŸ” FAISS Embedding Check")
114
+
115
+ check_button = gr.Button("πŸ”Ž Check FAISS Embeddings")
116
+ output_text = gr.Textbox(label="FAISS Status", interactive=False)
117
+
118
+ check_button.click(fn=check_faiss, outputs=output_text)
119
+
120
  # Launch Gradio app
121
  if __name__ == "__main__":
122
  demo.launch()