Update app.py
Browse files
app.py
CHANGED
|
@@ -22,18 +22,39 @@ def get_pdf_text(pdf_docs):
|
|
| 22 |
pdf_doc = pdf_loader.load() # ํ
์คํธ๋ฅผ ์ถ์ถํฉ๋๋ค.
|
| 23 |
return pdf_doc # ์ถ์ถํ ํ
์คํธ๋ฅผ ๋ฐํํฉ๋๋ค.
|
| 24 |
|
| 25 |
-
|
| 26 |
-
# ์๋ ํ
์คํธ ์ถ์ถ ํจ์๋ฅผ ์์ฑ
|
| 27 |
def get_text_file(docs):
|
| 28 |
-
|
| 29 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 30 |
def get_csv_file(docs):
|
| 31 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 32 |
|
| 33 |
def get_json_file(docs):
|
| 34 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 35 |
|
| 36 |
-
|
| 37 |
# ๋ฌธ์๋ค์ ์ฒ๋ฆฌํ์ฌ ํ
์คํธ ์ฒญํฌ๋ก ๋๋๋ ํจ์์
๋๋ค.
|
| 38 |
def get_text_chunks(documents):
|
| 39 |
text_splitter = RecursiveCharacterTextSplitter(
|
|
@@ -94,7 +115,7 @@ def handle_userinput(user_question):
|
|
| 94 |
|
| 95 |
def main():
|
| 96 |
load_dotenv()
|
| 97 |
-
st.set_page_config(page_title="Chat with multiple
|
| 98 |
page_icon=":books:")
|
| 99 |
st.write(css, unsafe_allow_html=True)
|
| 100 |
|
|
@@ -103,7 +124,7 @@ def main():
|
|
| 103 |
if "chat_history" not in st.session_state:
|
| 104 |
st.session_state.chat_history = None
|
| 105 |
|
| 106 |
-
st.header("Chat with multiple
|
| 107 |
user_question = st.text_input("Ask a question about your documents:")
|
| 108 |
if user_question:
|
| 109 |
handle_userinput(user_question)
|
|
|
|
| 22 |
pdf_doc = pdf_loader.load() # ํ
์คํธ๋ฅผ ์ถ์ถํฉ๋๋ค.
|
| 23 |
return pdf_doc # ์ถ์ถํ ํ
์คํธ๋ฅผ ๋ฐํํฉ๋๋ค.
|
| 24 |
|
| 25 |
+
|
|
|
|
| 26 |
def get_text_file(docs):
|
| 27 |
+
temp_dir = tempfile.TemporaryDirectory()
|
| 28 |
+
temp_filepath = os.path.join(temp_dir.name, docs.name)
|
| 29 |
+
with open(temp_filepath, "wb") as f:
|
| 30 |
+
f.write(docs.getvalue())
|
| 31 |
+
text_loader = TextLoader(temp_filepath)
|
| 32 |
+
text_doc = text_loader.load()
|
| 33 |
+
return text_doc
|
| 34 |
+
|
| 35 |
+
|
| 36 |
def get_csv_file(docs):
|
| 37 |
+
temp_dir = tempfile.TemporaryDirectory()
|
| 38 |
+
temp_filepath = os.path.join(temp_dir.name, docs.name)
|
| 39 |
+
with open(temp_filepath, "wb") as f:
|
| 40 |
+
f.write(docs.getvalue())
|
| 41 |
+
csv_loader = CSVLoader(temp_filepath)
|
| 42 |
+
csv_doc = csv_loader.load()
|
| 43 |
+
return csv_doc
|
| 44 |
|
| 45 |
def get_json_file(docs):
|
| 46 |
+
temp_dir = tempfile.TemporaryDirectory()
|
| 47 |
+
temp_filepath = os.path.join(temp_dir.name, docs.name)
|
| 48 |
+
with open(temp_filepath, "wb") as f:
|
| 49 |
+
f.write(docs.getvalue())
|
| 50 |
+
json_loader = JSONLoader(temp_filepath,
|
| 51 |
+
jq_schema='.scans[].relationships',
|
| 52 |
+
text_content=False)
|
| 53 |
+
|
| 54 |
+
json_doc = json_loader.load()
|
| 55 |
+
# print('json_doc = ',json_doc)
|
| 56 |
+
return json_doc
|
| 57 |
|
|
|
|
| 58 |
# ๋ฌธ์๋ค์ ์ฒ๋ฆฌํ์ฌ ํ
์คํธ ์ฒญํฌ๋ก ๋๋๋ ํจ์์
๋๋ค.
|
| 59 |
def get_text_chunks(documents):
|
| 60 |
text_splitter = RecursiveCharacterTextSplitter(
|
|
|
|
| 115 |
|
| 116 |
def main():
|
| 117 |
load_dotenv()
|
| 118 |
+
st.set_page_config(page_title="Chat with multiple PDFs",
|
| 119 |
page_icon=":books:")
|
| 120 |
st.write(css, unsafe_allow_html=True)
|
| 121 |
|
|
|
|
| 124 |
if "chat_history" not in st.session_state:
|
| 125 |
st.session_state.chat_history = None
|
| 126 |
|
| 127 |
+
st.header("Chat with multiple PDFs :books:")
|
| 128 |
user_question = st.text_input("Ask a question about your documents:")
|
| 129 |
if user_question:
|
| 130 |
handle_userinput(user_question)
|