Update app.py
Browse files
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)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 40 |
# result = helper(text_splitter) # Call helper to process text chunks
|
| 41 |
-
return
|
| 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 |
-
|
| 67 |
-
|
| 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()
|