EUNSEO56 commited on
Commit
fa6b94d
·
1 Parent(s): fab6ae4

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +21 -8
app.py CHANGED
@@ -29,18 +29,31 @@ def get_pdf_text(pdf_docs):
29
  # 아래 텍스트 추출 함수를 작성
30
 
31
  def get_text_file(docs):
32
- text_list = []
33
- for file in docs:
34
- if file.type == 'text/plain':
35
- text_lost.append(file.read().decode('utf-8'))
36
- return text_list
37
-
 
38
 
39
  def get_csv_file(docs):
40
- pass
 
 
 
 
 
 
41
 
42
  def get_json_file(docs):
43
- pass
 
 
 
 
 
 
44
 
45
 
46
  # 문서들을 처리하여 텍스트 청크로 나누는 함수입니다.
 
29
  # 아래 텍스트 추출 함수를 작성
30
 
31
  def get_text_file(docs):
32
+ temp_dir2 = tempfile.TemporaryDirectory()
33
+ temp_filepath2 = os.path.join(temp_dir2.name, text_docs.name)
34
+ with open(temp_filepath2, "wb") as f:
35
+ f.write(text_docs.getvalue())
36
+ text_loader = TextLoader(temp_filepath2)
37
+ text_doc = text_loader.load()
38
+ return text_doc
39
 
40
  def get_csv_file(docs):
41
+ temp_dir3 = tempfile.TemporaryDirectory() # 임시 디렉토리를 생성합니다.
42
+ temp_filepath3 = os.path.join(temp_dir.name, csv_docs.name) # 임시 파일 경로를 생성합니다.
43
+ with open(temp_filepath3, "wb") as f: # 임시 파일을 바이너리 쓰기 모드로 엽니다.
44
+ f.write(csv_docs.getvalue()) # PDF 문서의 내용을 임시 파일에 씁니다.
45
+ csv_loader = CSVLoader(temp_filepath3) # PyPDFLoader를 사용해 PDF를 로드합니다.
46
+ csv_doc = csv_loader.load() # 텍스트를 추출합니다.
47
+ return csv_doc # 추출한 텍스트를 반환합니다.
48
 
49
  def get_json_file(docs):
50
+ temp_dir4 = tempfile.TemporaryDirectory() # 임시 디렉토리를 생성합니다.
51
+ temp_filepath4 = os.path.join(temp_dir.name, json_docs.name) # 임시 파일 경로를 생성합니다.
52
+ with open(temp_filepath4, "wb") as f: # 임시 파일을 바이너리 쓰기 모드로 엽니다.
53
+ f.write(json_docs.getvalue()) # PDF 문서의 내용을 임시 파일에 씁니다.
54
+ json_loader = JSONLoader(temp_filepath4) # PyPDFLoader를 사용해 PDF를 로드합니다.
55
+ json_doc = json_loader.load() # 텍스트를 추출합니다.
56
+ return json_doc # 추출한 텍스트를 반환합니다.
57
 
58
 
59
  # 문서들을 처리하여 텍스트 청크로 나누는 함수입니다.