Spaces:
Sleeping
Sleeping
sankar12345
commited on
Commit
•
cac7383
1
Parent(s):
eb23a74
Update app.py
Browse files
app.py
CHANGED
@@ -11,12 +11,6 @@ from langchain.chains import ConversationalRetrievalChain
|
|
11 |
from htmlTemplates import css, bot_template, user_template
|
12 |
from langchain.llms import HuggingFaceHub
|
13 |
|
14 |
-
# Load environment variables from .env file
|
15 |
-
load_dotenv()
|
16 |
-
|
17 |
-
# Get Hugging Face token from environment variables
|
18 |
-
HUGGINGFACE_TOKEN = os.getenv("HUGGINGFACE_TOKEN")
|
19 |
-
|
20 |
def get_pdf_text(pdf_docs):
|
21 |
text = ""
|
22 |
for pdf in pdf_docs:
|
@@ -39,14 +33,14 @@ def get_text_chunks(text):
|
|
39 |
|
40 |
def get_vectorstore(text_chunks):
|
41 |
# embeddings = OpenAIEmbeddings()
|
42 |
-
embeddings = HuggingFaceInstructEmbeddings(model_name="hkunlp/instructor-xl")
|
43 |
vectorstore = FAISS.from_texts(texts=text_chunks, embedding=embeddings)
|
44 |
return vectorstore
|
45 |
|
46 |
|
47 |
def get_conversation_chain(vectorstore):
|
48 |
# llm = ChatOpenAI()
|
49 |
-
llm = HuggingFaceHub(repo_id="google/flan-t5-xxl", model_kwargs={"temperature":0.5, "max_length":512})
|
50 |
|
51 |
memory = ConversationBufferMemory(
|
52 |
memory_key='chat_history', return_messages=True)
|
@@ -108,4 +102,4 @@ def main():
|
|
108 |
|
109 |
|
110 |
if __name__ == '__main__':
|
111 |
-
main()
|
|
|
11 |
from htmlTemplates import css, bot_template, user_template
|
12 |
from langchain.llms import HuggingFaceHub
|
13 |
|
|
|
|
|
|
|
|
|
|
|
|
|
14 |
def get_pdf_text(pdf_docs):
|
15 |
text = ""
|
16 |
for pdf in pdf_docs:
|
|
|
33 |
|
34 |
def get_vectorstore(text_chunks):
|
35 |
# embeddings = OpenAIEmbeddings()
|
36 |
+
embeddings = HuggingFaceInstructEmbeddings(model_name="hkunlp/instructor-xl", token=os.getenv("HUGGING_FACE_TOKEN"))
|
37 |
vectorstore = FAISS.from_texts(texts=text_chunks, embedding=embeddings)
|
38 |
return vectorstore
|
39 |
|
40 |
|
41 |
def get_conversation_chain(vectorstore):
|
42 |
# llm = ChatOpenAI()
|
43 |
+
llm = HuggingFaceHub(repo_id="google/flan-t5-xxl", model_kwargs={"temperature":0.5, "max_length":512}, token=os.getenv("HUGGING_FACE_TOKEN"))
|
44 |
|
45 |
memory = ConversationBufferMemory(
|
46 |
memory_key='chat_history', return_messages=True)
|
|
|
102 |
|
103 |
|
104 |
if __name__ == '__main__':
|
105 |
+
main()
|