Anne31415 commited on
Commit
0cba2f4
·
1 Parent(s): 2c1ff12

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +33 -0
app.py CHANGED
@@ -101,6 +101,39 @@ def display_chat_history(chat_history):
101
  background_color = "#FFA07A" if sender == "User" else "#caf"
102
  st.markdown(f"<div style='background-color: {background_color}; padding: 10px; border-radius: 10px; margin: 10px;'>{sender}: {msg}</div>", unsafe_allow_html=True)
103
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
104
  def main():
105
  hide_streamlit_style = """
106
  <style>
 
101
  background_color = "#FFA07A" if sender == "User" else "#caf"
102
  st.markdown(f"<div style='background-color: {background_color}; padding: 10px; border-radius: 10px; margin: 10px;'>{sender}: {msg}</div>", unsafe_allow_html=True)
103
 
104
+
105
+ def load_pdf(file_path):
106
+ pdf_reader = PdfReader(file_path)
107
+ text = ""
108
+ for page in pdf_reader.pages:
109
+ text += page.extract_text()
110
+
111
+ text_splitter = RecursiveCharacterTextSplitter(
112
+ chunk_size=1000,
113
+ chunk_overlap=200,
114
+ length_function=len
115
+ )
116
+ chunks = text_splitter.split_text(text=text)
117
+
118
+ store_name, _ = os.path.splitext(os.path.basename(file_path))
119
+
120
+ if os.path.exists(f"{store_name}.pkl"):
121
+ with open(f"{store_name}.pkl", "rb") as f:
122
+ VectorStore = pickle.load(f)
123
+ else:
124
+ embeddings = OpenAIEmbeddings()
125
+ VectorStore = FAISS.from_texts(chunks, embedding=embeddings)
126
+ with open(f"{store_name}.pkl", "wb") as f:
127
+ pickle.dump(VectorStore, f)
128
+
129
+ return VectorStore
130
+
131
+
132
+
133
+ def load_chatbot():
134
+ return load_qa_chain(llm=OpenAI(), chain_type="stuff")
135
+
136
+
137
  def main():
138
  hide_streamlit_style = """
139
  <style>