tony346 commited on
Commit
1ff0128
ยท
verified ยท
1 Parent(s): d55c1c9

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +30 -9
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
- pass
29
-
 
 
 
 
 
 
 
30
  def get_csv_file(docs):
31
- pass
 
 
 
 
 
 
32
 
33
  def get_json_file(docs):
34
- pass
 
 
 
 
 
 
 
 
 
 
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 Files",
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 Files:")
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)