-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest.txt
100 lines (78 loc) · 3.14 KB
/
test.txt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
# import os
# import pickle
# import streamlit as st
# from PyPDF2 import PdfReader
# from dotenv import load_dotenv
# from streamlit_extras.add_vertical_space import add_vertical_space
# from langchain.llms import OpenAI
# from langchain.vectorstores import FAISS
# from langchain.chat_models import ChatOpenAI
# from langchain.callbacks import get_openai_callback
# from langchain.embeddings.openai import OpenAIEmbeddings
# from langchain.chains.question_answering import load_qa_chain
# from langchain.text_splitter import RecursiveCharacterTextSplitter
# from flask import Flask, request, jsonify
# app = Flask(__name__)
# @app.route('/pdf-reader', methods=['POST'])
# def pdf_reader():
# data = request.json
# # Extract parameters from the data (e.g., PDF file URL or content)
# pdf_url = data.get('pdf_url')
# query = data.get('query')
# response_data = {
# 'result': "Your response here",
# # Include any relevant data to send back to Munir-GPT
# }
# return jsonify(response_data)
# st.header("Chat with PDF 💬")
# # Sidebar contents
# with st.sidebar:
# st.title('Munir PDF-Reader')
# st.markdown('''
# ## About
# Hey there! I'm an AI-powered PDF tool ready to extract meaning from documents and have conversations about the content. Just upload a file and you can query me just like you would query a human who read the material. Give it a try!
# ''')
# add_vertical_space(26)
# st.header(
# 'Extension of Munir-GPT')
# load_dotenv()
# def main():
# # Upload the PDF File
# pdf = st.file_uploader("Upload a PDF file", type=["pdf"])
# # Read the PDF file
# if pdf is not None:
# pdf_reader = PdfReader(pdf)
# # Extract the text from the PDF
# text = ""
# for page in pdf_reader.pages:
# text += page.extract_text()
# text_splitter = RecursiveCharacterTextSplitter(
# chunk_size=1000,
# chunk_overlap=200,
# length_function=len,
# )
# chunks = text_splitter.split_text(text=text)
# # Embeddings
# store_name = pdf.name[:-4]
# # Check if the store exists
# if os.path.exists(f"{store_name}.pkl"):
# with open(f"{store_name}.pkl", "rb") as f:
# VectorStore = pickle.load(f)
# else: # Create the store
# embeddings = OpenAIEmbeddings()
# VectorStore = FAISS.from_texts(chunks, embedding=embeddings)
# with open(f"{store_name}.pkl", "wb") as f:
# pickle.dump(VectorStore, f)
# # Ask questions
# query = st.text_input("Ask questions about your document:")
# if query:
# docs = VectorStore.similarity_search(query=query, k=3)
# # Load the Open AI Language Model
# llm = OpenAI(model_name='gpt-3.5-turbo')
# chain = load_qa_chain(llm=llm, chain_type="stuff")
# with get_openai_callback() as cb:
# response = chain.run(input_documents=docs, question=query)
# print(cb)
# st.write(response)
# if __name__ == '__main__':
# app.run(debug=True)