Yoxas commited on
Commit
772fe4c
·
verified ·
1 Parent(s): fe3ee42

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +8 -8
app.py CHANGED
@@ -16,7 +16,7 @@ dataset = load_dataset("Yoxas/statistical_literacyv2")
16
 
17
  data = dataset["train"]
18
 
19
- # Convert the string embeddings to numerical arrays and ensure they are 2D
20
  def convert_and_ensure_2d_embeddings(example):
21
  embedding_str = example['embedding']
22
  embedding_str = embedding_str.replace('\n', ' ').replace('...', '')
@@ -39,8 +39,8 @@ def flatten_embeddings(example):
39
 
40
  data = data.map(flatten_embeddings)
41
 
42
- # Ensure embeddings are in the correct shape for FAISS
43
- embeddings = np.array([example['embedding'] for example in data], dtype=np.float32)
44
 
45
  # Add FAISS index
46
  data = data.add_faiss_index_from_external_arrays("embedding", embeddings)
@@ -131,11 +131,11 @@ TITLE = "# RAG"
131
 
132
  DESCRIPTION = """
133
  A RAG pipeline with a chatbot feature
134
- Resources used to build this project :
135
- * Embedding model : https://huggingface.co/mixedbread-ai/mxbai-embed-large-v1
136
- * Dataset : https://huggingface.co/datasets/not-lain/wikipedia
137
- * FAISS docs : https://huggingface.co/docs/datasets/v2.18.0/en/package_reference/main_classes#datasets.Dataset.add_faiss_index
138
- * Chatbot : https://huggingface.co/meta-llama/Meta-Llama-3-8B-Instruct
139
  """
140
 
141
  demo = gr.ChatInterface(
 
16
 
17
  data = dataset["train"]
18
 
19
+ # Convert string embeddings to numpy arrays and ensure they are 2D
20
  def convert_and_ensure_2d_embeddings(example):
21
  embedding_str = example['embedding']
22
  embedding_str = embedding_str.replace('\n', ' ').replace('...', '')
 
39
 
40
  data = data.map(flatten_embeddings)
41
 
42
+ # Extract embeddings and convert to numpy array
43
+ embeddings = np.vstack([example['embedding'] for example in data])
44
 
45
  # Add FAISS index
46
  data = data.add_faiss_index_from_external_arrays("embedding", embeddings)
 
131
 
132
  DESCRIPTION = """
133
  A RAG pipeline with a chatbot feature
134
+ Resources used to build this project:
135
+ * Embedding model: https://huggingface.co/mixedbread-ai/mxbai-embed-large-v1
136
+ * Dataset: https://huggingface.co/datasets/not-lain/wikipedia
137
+ * FAISS docs: https://huggingface.co/docs/datasets/v2.18.0/en/package_reference/main_classes#datasets.Dataset.add_faiss_index
138
+ * Chatbot: https://huggingface.co/meta-llama/Meta-Llama-3-8B-Instruct
139
  """
140
 
141
  demo = gr.ChatInterface(