pracheeeeez commited on
Commit
8ae6f96
·
verified ·
1 Parent(s): c299e27

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +11 -2
app.py CHANGED
@@ -10,7 +10,8 @@ from langchain.llms import HuggingFaceHub
10
  from htmltemplates import css, bot_template, user_template
11
 
12
  def get_text_chunks(text):
13
- text_splitter = RecursiveCharacterTextSplitter(
 
14
 
15
  chunk_size=1000,
16
  chunk_overlap=200,
@@ -18,6 +19,10 @@ def get_text_chunks(text):
18
  )
19
  chunks = text_splitter.split_text(text)
20
  return chunks
 
 
 
 
21
 
22
  def get_pdf_text(pdf_docs):
23
  text = ""
@@ -28,9 +33,13 @@ def get_pdf_text(pdf_docs):
28
  return text
29
 
30
  def get_vectorstore(text_chunks):
31
- embeddings = HuggingFaceInstructEmbeddings(model_name="hkunlp/instructor-xl")
 
32
  vectorstore = FAISS.from_texts(texts=text_chunks, embedding=embeddings)
33
  return vectorstore
 
 
 
34
 
35
  def get_conversation_chain(vectorstore):
36
  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
 
12
  def get_text_chunks(text):
13
+ try:
14
+ text_splitter = RecursiveCharacterTextSplitter(
15
 
16
  chunk_size=1000,
17
  chunk_overlap=200,
 
19
  )
20
  chunks = text_splitter.split_text(text)
21
  return chunks
22
+ except Exception as e:
23
+ st.error(f"Error in get_text_chunks:{e}")
24
+ return []
25
+
26
 
27
  def get_pdf_text(pdf_docs):
28
  text = ""
 
33
  return text
34
 
35
  def get_vectorstore(text_chunks):
36
+ try:
37
+ embeddings = HuggingFaceInstructEmbeddings(model_name="hkunlp/instructor-xl")
38
  vectorstore = FAISS.from_texts(texts=text_chunks, embedding=embeddings)
39
  return vectorstore
40
+ except Exception as e:
41
+ st.error(f"Error in get_vectorstore:{e}")
42
+ return None
43
 
44
  def get_conversation_chain(vectorstore):
45
  llm = HuggingFaceHub(repo_id="google/flan-t5-xxl", model_kwargs={"temperature": 0.5, "max_length": 512})