Update app.py
Browse files
app.py
CHANGED
@@ -29,31 +29,28 @@ def get_pdf_text(pdf_docs):
|
|
29 |
# μλ ν
μ€νΈ μΆμΆ ν¨μλ₯Ό μμ±
|
30 |
|
31 |
def get_text_file(docs):
|
32 |
-
|
33 |
-
|
34 |
-
|
35 |
-
|
36 |
-
|
|
|
37 |
|
38 |
def get_csv_file(docs):
|
39 |
-
|
40 |
-
|
41 |
-
|
42 |
-
|
43 |
-
|
44 |
-
|
45 |
-
else:
|
46 |
-
st.warning("Unsupported file type for get_csv_file")
|
47 |
|
48 |
def get_json_file(docs):
|
49 |
-
|
50 |
-
|
51 |
-
|
52 |
-
|
53 |
-
|
54 |
-
|
55 |
-
else:
|
56 |
-
st.warning("Unsupported file type for get_json_file")
|
57 |
|
58 |
|
59 |
# λ¬Έμλ€μ μ²λ¦¬νμ¬ ν
μ€νΈ μ²ν¬λ‘ λλλ ν¨μμ
λλ€.
|
@@ -155,32 +152,33 @@ def main():
|
|
155 |
docs = st.file_uploader(
|
156 |
"Upload your documents here and click on 'Process'", accept_multiple_files=True)
|
157 |
if st.button("Process"):
|
158 |
-
|
159 |
-
|
160 |
-
|
161 |
-
|
162 |
-
|
163 |
-
|
164 |
-
|
165 |
-
|
166 |
-
|
167 |
-
|
168 |
-
|
169 |
-
|
170 |
-
|
171 |
-
|
172 |
-
|
173 |
-
|
174 |
-
|
175 |
-
|
176 |
-
|
177 |
-
|
178 |
-
|
179 |
-
|
180 |
-
|
181 |
-
|
182 |
-
|
183 |
-
|
|
|
184 |
|
185 |
|
186 |
if __name__ == '__main__':
|
|
|
29 |
# μλ ν
μ€νΈ μΆμΆ ν¨μλ₯Ό μμ±
|
30 |
|
31 |
def get_text_file(docs):
|
32 |
+
text_list = []
|
33 |
+
for file in docs:
|
34 |
+
if file.type == 'text/plain':
|
35 |
+
# file is .txt
|
36 |
+
text_list.append(file.getvalue().decode('utf-8'))
|
37 |
+
return text_list
|
38 |
|
39 |
def get_csv_file(docs):
|
40 |
+
csv_list = []
|
41 |
+
for file in docs:
|
42 |
+
if file.type == 'text/csv':
|
43 |
+
# file is .csv
|
44 |
+
csv_list.extend(csv.reader(file.getvalue().decode('utf-8').splitlines()))
|
45 |
+
return csv_list
|
|
|
|
|
46 |
|
47 |
def get_json_file(docs):
|
48 |
+
json_list = []
|
49 |
+
for file in docs:
|
50 |
+
if file.type == 'application/json':
|
51 |
+
# file is .json
|
52 |
+
json_list.extend(json.load(file))
|
53 |
+
return json_list
|
|
|
|
|
54 |
|
55 |
|
56 |
# λ¬Έμλ€μ μ²λ¦¬νμ¬ ν
μ€νΈ μ²ν¬λ‘ λλλ ν¨μμ
λλ€.
|
|
|
152 |
docs = st.file_uploader(
|
153 |
"Upload your documents here and click on 'Process'", accept_multiple_files=True)
|
154 |
if st.button("Process"):
|
155 |
+
with st.spinner("Processing"):
|
156 |
+
# get pdf text
|
157 |
+
doc_list = []
|
158 |
+
|
159 |
+
for file in docs:
|
160 |
+
print('file - type : ', file.type)
|
161 |
+
if file.type == 'text/plain':
|
162 |
+
# file is .txt
|
163 |
+
doc_list.extend(get_text_file([file]))
|
164 |
+
elif file.type in ['application/octet-stream', 'application/pdf']:
|
165 |
+
# file is .pdf
|
166 |
+
doc_list.extend(get_pdf_text(file))
|
167 |
+
elif file.type == 'text/csv':
|
168 |
+
# file is .csv
|
169 |
+
doc_list.extend(get_csv_file([file]))
|
170 |
+
elif file.type == 'application/json':
|
171 |
+
# file is .json
|
172 |
+
doc_list.extend(get_json_file([file]))
|
173 |
+
|
174 |
+
# get the text chunks
|
175 |
+
text_chunks = get_text_chunks(doc_list)
|
176 |
+
|
177 |
+
# create vector store
|
178 |
+
vectorstore = get_vectorstore(text_chunks)
|
179 |
+
|
180 |
+
# create conversation chain
|
181 |
+
st.session_state.conversation = get_conversation_chain(vectorstore)
|
182 |
|
183 |
|
184 |
if __name__ == '__main__':
|