Blueccc commited on
Commit
262a171
β€’
1 Parent(s): eee3726

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +34 -12
app.py CHANGED
@@ -28,15 +28,33 @@ def get_pdf_text(pdf_docs):
28
  # 과제
29
  # μ•„λž˜ ν…μŠ€νŠΈ μΆ”μΆœ ν•¨μˆ˜λ₯Ό μž‘μ„±
30
 
31
- def get_text_file(docs):
32
- pass
33
-
34
-
35
- def get_csv_file(docs):
36
- pass
37
-
38
- def get_json_file(docs):
39
- pass
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
40
 
41
 
42
  # λ¬Έμ„œλ“€μ„ μ²˜λ¦¬ν•˜μ—¬ ν…μŠ€νŠΈ 청크둜 λ‚˜λˆ„λŠ” ν•¨μˆ˜μž…λ‹ˆλ‹€.
@@ -94,8 +112,8 @@ 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
 
101
  if "conversation" not in st.session_state:
@@ -103,7 +121,11 @@ def main():
103
  if "chat_history" not in st.session_state:
104
  st.session_state.chat_history = None
105
 
 
 
 
106
  st.header("Assign 8 -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)
@@ -115,7 +137,7 @@ def main():
115
 
116
  st.subheader("Your documents")
117
  docs = st.file_uploader(
118
- "Upload your PDFs here and click on 'Process'", accept_multiple_files=True)
119
  if st.button("Process"):
120
  with st.spinner("Processing"):
121
  # get pdf text
 
28
  # 과제
29
  # μ•„λž˜ ν…μŠ€νŠΈ μΆ”μΆœ ν•¨μˆ˜λ₯Ό μž‘μ„±
30
 
31
+ def get_text_file(txt_files):
32
+ temp_dir = tempfile.TemporaryDirectory()
33
+ temp_filepath = os.path.join(temp_dir.name, txt_files.name)
34
+ with open(temp_filepath, "wb") as f:
35
+ f.write(txt_files.getvalue())
36
+ text_loader = TextLoader(temp_filepath)
37
+ text_file = text_loader.load()
38
+ return text_file
39
+
40
+
41
+ def get_csv_file(csv_files):
42
+ temp_dir = tempfile.TemporaryDirectory()
43
+ temp_filepath = os.path.join(temp_dir.name, csv_files.name)
44
+ with open(temp_filepath, "wb") as f:
45
+ f.write(csv_files.getvalue())
46
+ csv_loader = CSVLoader(temp_filepath)
47
+ csv_file = csv_loader.load()
48
+ return csv_file
49
+
50
+ def get_json_file(json_files):
51
+ temp_dir = tempfile.TemporaryDirectory()
52
+ temp_filepath = os.path.join(temp_dir.name, json_files.name)
53
+ with open(temp_filepath, "wb") as f:
54
+ f.write(json_files.getvalue())
55
+ json_loader = JSONLoader(temp_filepath, jq_schema='.messages[].content', text_content=False)
56
+ json_file = json_loader.load()
57
+ return json_file
58
 
59
 
60
  # λ¬Έμ„œλ“€μ„ μ²˜λ¦¬ν•˜μ—¬ ν…μŠ€νŠΈ 청크둜 λ‚˜λˆ„λŠ” ν•¨μˆ˜μž…λ‹ˆλ‹€.
 
112
 
113
  def main():
114
  load_dotenv()
115
+ st.set_page_config(page_title="Assign8: Chat with multiple Files",
116
+ page_icon=":random:")
117
  st.write(css, unsafe_allow_html=True)
118
 
119
  if "conversation" not in st.session_state:
 
121
  if "chat_history" not in st.session_state:
122
  st.session_state.chat_history = None
123
 
124
+ <<<<<<< HEAD
125
+ st.header("Assign8: Chat with multiple Files :")
126
+ =======
127
  st.header("Assign 8 -Chat with multiple Files :")
128
+ >>>>>>> eee37261f0a756aa7ad43f502da4241637d89427
129
  user_question = st.text_input("Ask a question about your documents:")
130
  if user_question:
131
  handle_userinput(user_question)
 
137
 
138
  st.subheader("Your documents")
139
  docs = st.file_uploader(
140
+ "Upload your Files here and click on 'Process'", accept_multiple_files=True)
141
  if st.button("Process"):
142
  with st.spinner("Processing"):
143
  # get pdf text