nijoow commited on
Commit
78f267a
Β·
1 Parent(s): 22b7b9d

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +14 -4
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(docs):
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(docs):
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(docs):
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))