chatbytes commited on
Commit
9b540af
·
verified ·
1 Parent(s): 1de9f37

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +42 -42
app.py CHANGED
@@ -1,47 +1,47 @@
1
  import gradio as gr
2
- from langchain_community.llms import GooglePalm
3
- from langchain_community.embeddings import HuggingFaceInstructEmbeddings
4
- from langchain.text_splitter import CharacterTextSplitter
5
- from langchain_community.embeddings import GooglePalmEmbeddings
6
- from langchain_community.vectorstores import FAISS
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
14
- history.append((user_input, bot_response))
15
- return history, history
16
 
17
- def text_splitter_function(text):
18
- text_splitter = CharacterTextSplitter(
19
- separator = '\n',
20
- chunk_size = 1000,
21
- chunk_overlap = 40,
22
- length_function = len,
23
- )
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:
@@ -61,5 +61,5 @@ with gr.Blocks() as demo:
61
  send_btn.click(chatbot_response,[user_input,state],[chatbot, state])
62
 
63
  if __name__ == "__main__":
64
- embeddings=GooglePalmEmbeddings(google_api_key=google_api)
65
  demo.launch()
 
1
  import gradio as gr
2
+ # from langchain_community.llms import GooglePalm
3
+ # from langchain_community.embeddings import HuggingFaceInstructEmbeddings
4
+ # from langchain.text_splitter import CharacterTextSplitter
5
+ # from langchain_community.embeddings import GooglePalmEmbeddings
6
+ # from langchain_community.vectorstores import FAISS
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
14
+ # history.append((user_input, bot_response))
15
+ # return history, history
16
 
17
+ # def text_splitter_function(text):
18
+ # text_splitter = CharacterTextSplitter(
19
+ # separator = '\n',
20
+ # chunk_size = 1000,
21
+ # chunk_overlap = 40,
22
+ # length_function = len,
23
+ # )
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:
 
61
  send_btn.click(chatbot_response,[user_input,state],[chatbot, state])
62
 
63
  if __name__ == "__main__":
64
+ # embeddings=GooglePalmEmbeddings(google_api_key=google_api)
65
  demo.launch()