Daoneeee commited on
Commit
0db9945
·
1 Parent(s): c5ee592

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +8 -3
app.py CHANGED
@@ -29,9 +29,14 @@ def get_pdf_text(pdf_docs):
29
  # 과제
30
  # 아래 텍스트 추출 함수를 작성
31
 
32
- def get_text_file(docs):
33
- text_loader = TextLoader(docs) # 텍스트 파일을 처리할 TextLoader 사용
34
- return text_loader.load()
 
 
 
 
 
35
 
36
  def get_csv_file(docs):
37
  csv_loader = CSVLoader(docs) # CSV 파일을 처리할 CSVLoader 사용
 
29
  # 과제
30
  # 아래 텍스트 추출 함수를 작성
31
 
32
+ def get_text_file(text_docs):
33
+ temp_dir = tempfile.TemporaryDirectory() # 임시 디렉토리를 생성합니다.
34
+ temp_filepath = os.path.join(temp_dir.name, text_docs.name) # 임시 파일 경로를 생성합니다.
35
+ with open(temp_filepath, "wb") as f: # 임시 파일을 바이너리 쓰기 모드로 엽니다.
36
+ f.write(text_docs.getvalue()) # PDF 문서의 내용을 임시 파일에 씁니다.
37
+ text_loader = TextLoader(temp_filepath) # PyPDFLoader를 사용해 PDF를 로드합니다.
38
+ text_doc = text_loader.load() # 텍스트를 추출합니다.
39
+ return text_doc # 추출한 텍스트를 반환합니다.
40
 
41
  def get_csv_file(docs):
42
  csv_loader = CSVLoader(docs) # CSV 파일을 처리할 CSVLoader 사용