Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
@@ -14,7 +14,17 @@ from langchain.document_loaders import PyPDFLoader, TextLoader, JSONLoader, CSVL
|
|
14 |
import tempfile # μμ νμΌμ μμ±νκΈ° μν λΌμ΄λΈλ¬λ¦¬μ
λλ€.
|
15 |
import os
|
16 |
|
17 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
18 |
# PDF λ¬Έμλ‘λΆν° ν
μ€νΈλ₯Ό μΆμΆνλ ν¨μμ
λλ€.
|
19 |
def get_pdf_text(pdf_docs):
|
20 |
temp_dir = tempfile.TemporaryDirectory() # μμ λλ ν 리λ₯Ό μμ±ν©λλ€.
|
@@ -28,19 +38,19 @@ def get_pdf_text(pdf_docs):
|
|
28 |
# κ³Όμ
|
29 |
# μλ ν
μ€νΈ μΆμΆ ν¨μλ₯Ό μμ±
|
30 |
|
31 |
-
def get_text_file(
|
32 |
text_list = []
|
33 |
for doc in docs:
|
34 |
text_list.append(get_text_from_text_file(doc))
|
35 |
return text_list
|
36 |
|
37 |
-
def get_csv_file(
|
38 |
text_list = []
|
39 |
for doc in docs:
|
40 |
text_list.append(get_text_from_csv_file(doc))
|
41 |
return text_list
|
42 |
|
43 |
-
def get_json_file(
|
44 |
text_list = []
|
45 |
for doc in docs:
|
46 |
text_list.append(get_text_from_json_file(doc))
|
|
|
14 |
import tempfile # μμ νμΌμ μμ±νκΈ° μν λΌμ΄λΈλ¬λ¦¬μ
λλ€.
|
15 |
import os
|
16 |
|
17 |
+
for file in docs:
|
18 |
+
print('file -type : ',file.type)
|
19 |
+
if file.type == 'text/plain' :
|
20 |
+
doc_list.extend(get_text_file(file))
|
21 |
+
elif file.type in ['application/octet-stream','application/pdf'] :
|
22 |
+
doc_list.extend(get_pdf_text(file))
|
23 |
+
elif file.type == 'text/csv' :
|
24 |
+
doc_list.extend(get_csv_file(file))
|
25 |
+
elif file.type == 'application/json' :
|
26 |
+
doc_list.extend(get_json_file(file))
|
27 |
+
|
28 |
# PDF λ¬Έμλ‘λΆν° ν
μ€νΈλ₯Ό μΆμΆνλ ν¨μμ
λλ€.
|
29 |
def get_pdf_text(pdf_docs):
|
30 |
temp_dir = tempfile.TemporaryDirectory() # μμ λλ ν 리λ₯Ό μμ±ν©λλ€.
|
|
|
38 |
# κ³Όμ
|
39 |
# μλ ν
μ€νΈ μΆμΆ ν¨μλ₯Ό μμ±
|
40 |
|
41 |
+
def get_text_file(txt_docs):
|
42 |
text_list = []
|
43 |
for doc in docs:
|
44 |
text_list.append(get_text_from_text_file(doc))
|
45 |
return text_list
|
46 |
|
47 |
+
def get_csv_file(csv_docs):
|
48 |
text_list = []
|
49 |
for doc in docs:
|
50 |
text_list.append(get_text_from_csv_file(doc))
|
51 |
return text_list
|
52 |
|
53 |
+
def get_json_file(json_docs):
|
54 |
text_list = []
|
55 |
for doc in docs:
|
56 |
text_list.append(get_text_from_json_file(doc))
|