1MR commited on
Commit
f29d9fb
·
verified ·
1 Parent(s): 5e6cda6

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +15 -4
app.py CHANGED
@@ -10,6 +10,8 @@ from langchain.chains import ConversationalRetrievalChain
10
  from htmlTemplates import css, bot_template, user_template
11
  from langchain_community.llms import HuggingFaceHub
12
  import os
 
 
13
  # from huggingface_hub import login
14
 
15
  # Retrieve the Hugging Face token from environment variables
@@ -33,11 +35,20 @@ def get_text_chunks(text):
33
  return chunks
34
 
35
  # token="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1"
 
 
 
 
 
 
36
  def get_vectorstore(text_chunks):
37
- # embeddings=HuggingFaceInstructEmbeddings(model_name="hkunlp/instructor-xl",huggingfacehub_token=os.getenv("TOKEN_API2"))
38
- embeddings=HuggingFaceInstructEmbeddings(model_name="hkunlp/instructor-xl")
39
- vectorstore = FAISS.from_texts(texts=text_chunks, embedding=embeddings)
40
- return vectorstore
 
 
 
41
 
42
  def get_conversation_chain(vectorstore):
43
  llm = HuggingFaceHub(repo_id="google/flan-t5-xxl", model_kwargs={"temperature":0.5, "max_length":512})
 
10
  from htmlTemplates import css, bot_template, user_template
11
  from langchain_community.llms import HuggingFaceHub
12
  import os
13
+ from sentence_transformers import SentenceTransformer
14
+
15
  # from huggingface_hub import login
16
 
17
  # Retrieve the Hugging Face token from environment variables
 
35
  return chunks
36
 
37
  # token="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1"
38
+ # def get_vectorstore(text_chunks):
39
+ # # embeddings=HuggingFaceInstructEmbeddings(model_name="hkunlp/instructor-xl",huggingfacehub_token=os.getenv("TOKEN_API2"))
40
+ # embeddings=HuggingFaceInstructEmbeddings(model_name="hkunlp/instructor-xl")
41
+ # vectorstore = FAISS.from_texts(texts=text_chunks, embedding=embeddings)
42
+ # return vectorstore
43
+
44
  def get_vectorstore(text_chunks):
45
+ # Load a SentenceTransformer model for embeddings
46
+ embedding_model = SentenceTransformer("hkunlp/instructor-xl") # Replace with a model of your choice
47
+ embeddings = [embedding_model.encode(chunk) for chunk in text_chunks]
48
+
49
+ # Create a FAISS vectorstore
50
+ vectorstore = FAISS.from_embeddings(embeddings=embeddings, texts=text_chunks)
51
+ return vectorstore
52
 
53
  def get_conversation_chain(vectorstore):
54
  llm = HuggingFaceHub(repo_id="google/flan-t5-xxl", model_kwargs={"temperature":0.5, "max_length":512})