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

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +16 -9
app.py CHANGED
@@ -10,7 +10,9 @@ 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 sentence_transformers import SentenceTransformer
 
 
14
 
15
  # from huggingface_hub import login
16
 
@@ -41,17 +43,22 @@ def get_text_chunks(text):
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})
55
  memory=ConversationBufferMemory(
56
  memory_key='chat_history',return_messages=True)
57
  conversation_chain = ConversationalRetrievalChain.from_llm(
 
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
+ from langchain_huggingface import HuggingFaceEmbeddings
15
+
16
 
17
  # from huggingface_hub import login
18
 
 
43
  # vectorstore = FAISS.from_texts(texts=text_chunks, embedding=embeddings)
44
  # return vectorstore
45
 
46
+ # def get_vectorstore(text_chunks):
47
+ # # Load a SentenceTransformer model for embeddings
48
+ # embedding_model = SentenceTransformer("hkunlp/instructor-xl") # Replace with a model of your choice
49
+ # embeddings = [embedding_model.encode(chunk) for chunk in text_chunks]
50
 
51
+ # # Create a FAISS vectorstore
52
+ # vectorstore = FAISS.from_embeddings(embeddings=embeddings, texts=text_chunks)
53
+ # return vectorstore
54
 
55
+ def get_vectorstore(text_chunks):
56
+ embeddings = HuggingFaceEmbeddings(model_name="sentence-transformers/all-MiniLM-L6-v2")
57
+ vectorstore = FAISS.from_texts(texts=text_chunks, embedding=embeddings)
58
+ return vectorstore
59
+
60
  def get_conversation_chain(vectorstore):
61
+ llm = HuggingFaceHub(repo_id="google/flan-t5-xxl", model_kwargs={"temperature":0.5, "max_length":512},huggingfacehub_api_token=os.getenv("TOKEN_API2"))
62
  memory=ConversationBufferMemory(
63
  memory_key='chat_history',return_messages=True)
64
  conversation_chain = ConversationalRetrievalChain.from_llm(