Spaces:
Build error
Build error
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,14 +1,12 @@
|
|
| 1 |
-
|
| 2 |
-
|
| 3 |
# Importing RunnableLambda for wrapping functions as runnable components.
|
| 4 |
-
|
| 5 |
-
|
| 6 |
-
|
| 7 |
-
|
| 8 |
# importing HuggingFace model abstraction class from langchain
|
| 9 |
-
from langchain_huggingface
|
| 10 |
-
from langchain.llms import HuggingFaceEndpoint
|
| 11 |
-
from sentence_transformers import SentenceTransformer
|
| 12 |
|
| 13 |
import torch
|
| 14 |
import gradio
|
|
@@ -28,9 +26,14 @@ llm = HuggingFaceEndpoint(
|
|
| 28 |
repetition_penalty=1.03, # Slightly penalizes repeated tokens to reduce redundancy in responses.
|
| 29 |
)
|
| 30 |
|
| 31 |
-
#
|
|
|
|
|
|
|
| 32 |
|
| 33 |
-
|
|
|
|
|
|
|
|
|
|
| 34 |
|
| 35 |
# Creating a Chroma vector database instance.
|
| 36 |
vectordb = Chroma(
|
|
|
|
| 1 |
+
from langchain_huggingface import HuggingFaceEmbeddings
|
| 2 |
+
from langchain_chroma import Chroma
|
| 3 |
# Importing RunnableLambda for wrapping functions as runnable components.
|
| 4 |
+
from langchain_core.runnables import RunnableLambda
|
| 5 |
+
from langchain_core.prompts import PromptTemplate # To format prompts
|
| 6 |
+
from langchain_core.output_parsers import StrOutputParser # to transform the output of an LLM into a more usable format
|
| 7 |
+
from langchain.schema.runnable import RunnableParallel, RunnablePassthrough
|
| 8 |
# importing HuggingFace model abstraction class from langchain
|
| 9 |
+
from langchain_huggingface import HuggingFaceEndpoint
|
|
|
|
|
|
|
| 10 |
|
| 11 |
import torch
|
| 12 |
import gradio
|
|
|
|
| 26 |
repetition_penalty=1.03, # Slightly penalizes repeated tokens to reduce redundancy in responses.
|
| 27 |
)
|
| 28 |
|
| 29 |
+
# Initializing the Hugging Face embedding model.
|
| 30 |
+
embedding = HuggingFaceEmbeddings(
|
| 31 |
+
model_name="mixedbread-ai/mxbai-embed-large-v1", # Using a pre-trained embedding model for text vectorization.
|
| 32 |
|
| 33 |
+
model_kwargs={'device': "cuda" if torch.cuda.is_available() else "cpu"}, # Configuring the model to use GPU if available.
|
| 34 |
+
|
| 35 |
+
encode_kwargs={'normalize_embeddings': False} # Disabling normalization to preserve the original embedding scale.
|
| 36 |
+
)
|
| 37 |
|
| 38 |
# Creating a Chroma vector database instance.
|
| 39 |
vectordb = Chroma(
|