Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -20,22 +20,23 @@ def embed_text(texts):
|
|
| 20 |
embeddings = model(**inputs).last_hidden_state.mean(dim=1)
|
| 21 |
return embeddings.numpy()
|
| 22 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 23 |
if "vector" not in st.session_state:
|
| 24 |
st.session_state.loader = WebBaseLoader("https://docs.nvidia.com/cuda/")
|
| 25 |
st.session_state.docs = st.session_state.loader.load()
|
| 26 |
|
| 27 |
st.session_state.text_splitter = RecursiveCharacterTextSplitter(chunk_size=1000, chunk_overlap=200)
|
| 28 |
documents = st.session_state.text_splitter.split_documents(st.session_state.docs[:50])
|
| 29 |
-
|
| 30 |
-
# Generate embeddings for documents
|
| 31 |
-
doc_texts = [doc.page_content for doc in documents]
|
| 32 |
-
embeddings = embed_text(doc_texts)
|
| 33 |
-
|
| 34 |
-
# Convert embeddings to list of lists for FAISS
|
| 35 |
-
embeddings = embeddings.tolist()
|
| 36 |
|
| 37 |
-
# Create FAISS index
|
| 38 |
-
st.session_state.vectors = FAISS.
|
|
|
|
|
|
|
|
|
|
| 39 |
|
| 40 |
st.title("ChatGroq Demo")
|
| 41 |
groq_api_key = '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'
|
|
|
|
| 20 |
embeddings = model(**inputs).last_hidden_state.mean(dim=1)
|
| 21 |
return embeddings.numpy()
|
| 22 |
|
| 23 |
+
def embedding_function(texts):
|
| 24 |
+
# This function converts texts to embeddings using the Hugging Face model
|
| 25 |
+
embeddings = embed_text(texts)
|
| 26 |
+
return embeddings
|
| 27 |
+
|
| 28 |
if "vector" not in st.session_state:
|
| 29 |
st.session_state.loader = WebBaseLoader("https://docs.nvidia.com/cuda/")
|
| 30 |
st.session_state.docs = st.session_state.loader.load()
|
| 31 |
|
| 32 |
st.session_state.text_splitter = RecursiveCharacterTextSplitter(chunk_size=1000, chunk_overlap=200)
|
| 33 |
documents = st.session_state.text_splitter.split_documents(st.session_state.docs[:50])
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 34 |
|
| 35 |
+
# Create FAISS index using the custom embedding function
|
| 36 |
+
st.session_state.vectors = FAISS.from_texts(
|
| 37 |
+
[doc.page_content for doc in documents],
|
| 38 |
+
embedding_function
|
| 39 |
+
)
|
| 40 |
|
| 41 |
st.title("ChatGroq Demo")
|
| 42 |
groq_api_key = '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'
|