Update app.py
Browse files
app.py
CHANGED
@@ -7,7 +7,7 @@ import gradio as gr
|
|
7 |
# from langchain_community.document_loaders import PyPDFLoader
|
8 |
# from langchain_community.chains import RetrievalQA
|
9 |
# from secret1 import GOOGLE_API as google_api
|
10 |
-
|
11 |
# def chatbot_response(user_input, history):
|
12 |
# # This is a placeholder function. Replace with your actual chatbot logic.
|
13 |
# bot_response = "You said: " + user_input
|
@@ -24,24 +24,24 @@ import gradio as gr
|
|
24 |
# texts = text_splitter.split_text(text)
|
25 |
# return texts;
|
26 |
|
27 |
-
|
28 |
-
|
29 |
-
#
|
30 |
-
|
31 |
-
#
|
32 |
-
|
33 |
-
|
34 |
-
|
35 |
-
|
36 |
-
#
|
37 |
-
#
|
38 |
-
#
|
39 |
-
#
|
40 |
-
#
|
41 |
-
#
|
42 |
-
#
|
43 |
-
#
|
44 |
-
|
45 |
|
46 |
|
47 |
with gr.Blocks() as demo:
|
@@ -57,7 +57,7 @@ with gr.Blocks() as demo:
|
|
57 |
with gr.Column():
|
58 |
input_file=gr.File(label="Upload PDF", file_count="single")
|
59 |
submit_btn=gr.Button("Submit")
|
60 |
-
|
61 |
#send_btn.click(chatbot_response,[user_input,state],[chatbot, state])
|
62 |
|
63 |
if __name__ == "__main__":
|
|
|
7 |
# from langchain_community.document_loaders import PyPDFLoader
|
8 |
# from langchain_community.chains import RetrievalQA
|
9 |
# from secret1 import GOOGLE_API as google_api
|
10 |
+
import PyPDF2
|
11 |
# def chatbot_response(user_input, history):
|
12 |
# # This is a placeholder function. Replace with your actual chatbot logic.
|
13 |
# bot_response = "You said: " + user_input
|
|
|
24 |
# texts = text_splitter.split_text(text)
|
25 |
# return texts;
|
26 |
|
27 |
+
def text_extract(file):
|
28 |
+
pdf_reader = PyPDF2.PdfReader(file.name)
|
29 |
+
# Get the number of pages
|
30 |
+
num_pages = len(pdf_reader.pages)
|
31 |
+
# Extract text from each page
|
32 |
+
text = ""
|
33 |
+
for page_num in range(num_pages):
|
34 |
+
page = pdf_reader.pages[page_num]
|
35 |
+
text += page.extract_text()
|
36 |
+
# text_splitter=text_splitter_function(text);
|
37 |
+
# db = FAISS.from_texts(text_splitter, embeddings);
|
38 |
+
# retriever = db.as_retriever(search_type="similarity", search_kwargs={"k": 2})
|
39 |
+
# llm=GooglePalm(google_api_key=google_api)
|
40 |
+
# qa = RetrievalQA.from_chain_type(
|
41 |
+
# llm=llm, chain_type="stuff", retriever=retriever, return_source_documents=True
|
42 |
+
# )
|
43 |
+
# print(db)
|
44 |
+
return text
|
45 |
|
46 |
|
47 |
with gr.Blocks() as demo:
|
|
|
57 |
with gr.Column():
|
58 |
input_file=gr.File(label="Upload PDF", file_count="single")
|
59 |
submit_btn=gr.Button("Submit")
|
60 |
+
submit_btn.click(text_extract, [input_file], [user_input])
|
61 |
#send_btn.click(chatbot_response,[user_input,state],[chatbot, state])
|
62 |
|
63 |
if __name__ == "__main__":
|