chatbytes commited on
Commit
fd7cb70
·
verified ·
1 Parent(s): a9a24c8

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +15 -4
app.py CHANGED
@@ -4,6 +4,7 @@ from langchain.embeddings import GooglePalmEmbeddings
4
  from langchain.vectorstores import FAISS
5
  from langchain.chains import RetrievalQA
6
  from langchain.llms import GooglePalm
 
7
  from langchain.text_splitter import CharacterTextSplitter
8
  # Define chatbot response function
9
  def chatbot_response(user_input):
@@ -36,9 +37,19 @@ def text_extract(file):
36
  for page_num in range(num_pages):
37
  page = pdf_reader.pages[page_num]
38
  text += page.extract_text() or ""
39
- text_splitter = text_splitter_function(text) # Split extracted text into chunks
 
 
 
 
 
 
 
 
 
 
40
  # result = helper(text_splitter) # Call helper to process text chunks
41
- return text_splitter
42
 
43
  # Define Gradio interface
44
  with gr.Blocks() as demo:
@@ -63,6 +74,6 @@ with gr.Blocks() as demo:
63
 
64
  # Initialize embeddings and launch the app
65
  if __name__ == "__main__":
66
- google_api_key = "YOUR_GOOGLE_API_KEY" # Replace with your actual Google API key
67
- embeddings = GooglePalmEmbeddings(google_api_key=google_api_key)
68
  demo.launch()
 
4
  from langchain.vectorstores import FAISS
5
  from langchain.chains import RetrievalQA
6
  from langchain.llms import GooglePalm
7
+ from secret1 import GOOGLE_API as google_api
8
  from langchain.text_splitter import CharacterTextSplitter
9
  # Define chatbot response function
10
  def chatbot_response(user_input):
 
37
  for page_num in range(num_pages):
38
  page = pdf_reader.pages[page_num]
39
  text += page.extract_text() or ""
40
+ text_splitter = text_splitter_function(text)
41
+ embeddings = GooglePalmEmbeddings(google_api_key=google_api)
42
+ db = FAISS.from_texts(text_splitter, embeddings)
43
+ retriever = db.as_retriever(search_type="similarity", search_kwargs={"k": 2})
44
+ llm=GooglePalm(google_api_key=google_api)
45
+ qa = RetrievalQA.from_chain_type(
46
+ llm=llm, chain_type="stuff", retriever=retriever, return_source_documents=True
47
+ )
48
+ result1 = qa.invoke(({"query":}))
49
+ print("FitBot:",result1['result'])
50
+ # Split extracted text into chunks
51
  # result = helper(text_splitter) # Call helper to process text chunks
52
+ return result1['result']
53
 
54
  # Define Gradio interface
55
  with gr.Blocks() as demo:
 
74
 
75
  # Initialize embeddings and launch the app
76
  if __name__ == "__main__":
77
+ # Replace with your actual Google API key
78
+
79
  demo.launch()