Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
@@ -19,7 +19,10 @@ data = dataset["train"]
|
|
19 |
# Convert the string embeddings to numerical arrays
|
20 |
def convert_and_ensure_2d_embeddings(example):
|
21 |
# Convert the string to a numpy array
|
22 |
-
|
|
|
|
|
|
|
23 |
# Ensure the embeddings are 2-dimensional
|
24 |
if embeddings.ndim == 1:
|
25 |
embeddings = embeddings.reshape(1, -1)
|
@@ -34,7 +37,7 @@ model_id = "meta-llama/Meta-Llama-3-8B-Instruct"
|
|
34 |
|
35 |
# use quantization to lower GPU usage
|
36 |
bnb_config = BitsAndBytesConfig(
|
37 |
-
|
38 |
)
|
39 |
|
40 |
tokenizer = AutoTokenizer.from_pretrained(model_id, token=token)
|
@@ -119,23 +122,4 @@ A rag pipeline with a chatbot feature
|
|
119 |
Resources used to build this project :
|
120 |
* embedding model : https://huggingface.co/mixedbread-ai/mxbai-embed-large-v1
|
121 |
* dataset : https://huggingface.co/datasets/not-lain/wikipedia
|
122 |
-
* faiss docs : https://huggingface.co/docs/datasets/v2.18.0/en/package_reference/main_classes#datasets
|
123 |
-
* chatbot : https://huggingface.co/meta-llama/Meta-Llama-3-8B-Instruct
|
124 |
-
"""
|
125 |
-
|
126 |
-
demo = gr.ChatInterface(
|
127 |
-
fn=talk,
|
128 |
-
chatbot=gr.Chatbot(
|
129 |
-
show_label=True,
|
130 |
-
show_share_button=True,
|
131 |
-
show_copy_button=True,
|
132 |
-
likeable=True,
|
133 |
-
layout="bubble",
|
134 |
-
bubble_full_width=False,
|
135 |
-
),
|
136 |
-
theme="Soft",
|
137 |
-
examples=[["what's anarchy ? "]],
|
138 |
-
title=TITLE,
|
139 |
-
description=DESCRIPTION,
|
140 |
-
)
|
141 |
-
demo.launch(debug=True)
|
|
|
19 |
# Convert the string embeddings to numerical arrays
|
20 |
def convert_and_ensure_2d_embeddings(example):
|
21 |
# Convert the string to a numpy array
|
22 |
+
embedding_str = example['embedding']
|
23 |
+
embedding_str = embedding_str.replace('\n', ' ')
|
24 |
+
embedding_list = list(map(float, embedding_str.strip("[]").split()))
|
25 |
+
embeddings = np.array(embedding_list, dtype=np.float32)
|
26 |
# Ensure the embeddings are 2-dimensional
|
27 |
if embeddings.ndim == 1:
|
28 |
embeddings = embeddings.reshape(1, -1)
|
|
|
37 |
|
38 |
# use quantization to lower GPU usage
|
39 |
bnb_config = BitsAndBytesConfig(
|
40 |
+
load_in 4bit=True, bnb_4bit_use_double_quant=True, bnb_4bit_quant_type="nf4", bnb_4bit_compute_dtype=torch.bfloat16
|
41 |
)
|
42 |
|
43 |
tokenizer = AutoTokenizer.from_pretrained(model_id, token=token)
|
|
|
122 |
Resources used to build this project :
|
123 |
* embedding model : https://huggingface.co/mixedbread-ai/mxbai-embed-large-v1
|
124 |
* dataset : https://huggingface.co/datasets/not-lain/wikipedia
|
125 |
+
* faiss docs : https://huggingface.co/docs/datasets/v2.18.0/en/package_reference/main_classes#datasets
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|