bin20 commited on
Commit
8fcbf8b
·
1 Parent(s): 99e260f

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +8 -4
app.py CHANGED
@@ -25,14 +25,18 @@ def get_pdf_text(pdf_docs):
25
  # 과제
26
  # 아래 텍스트 추출 함수를 작성
27
  def get_text_file(text_data):
28
- temp_dir = tempfile.TemporaryDirectory()
29
- temp_filepath = os.path.join(temp_dir.name, text_data.name)
30
- with open(temp_filepath, "w", encoding="utf-8") as textfile:
31
- textfile.write(text_data.getvalue().decode('utf-8'))
 
 
32
  text_loader = TextLoader(temp_filepath)
33
  text = text_loader.load()
 
34
  return text
35
 
 
36
  def get_csv_text(csv_file):
37
  temp_dir = tempfile.TemporaryDirectory()
38
  temp_filepath = os.path.join(temp_dir.name, csv_file.name)
 
25
  # 과제
26
  # 아래 텍스트 추출 함수를 작성
27
  def get_text_file(text_data):
28
+ temp_dir = tempfile.TemporaryDirectory() # 임시 디렉토리 생성
29
+ temp_filepath = os.path.join(temp_dir.name, text_data.name) # 임시 파일 경로 생성
30
+ with open(temp_filepath, "wb") as f: # 임시 파일을 바이너리 쓰기 모드로 열기
31
+ f.write(text_data.getvalue()) # 텍스트 데이터를 임시 파일에 쓰기
32
+
33
+ # 임시 파일을 TextLoader로 로드하여 텍스트 추출
34
  text_loader = TextLoader(temp_filepath)
35
  text = text_loader.load()
36
+
37
  return text
38
 
39
+
40
  def get_csv_text(csv_file):
41
  temp_dir = tempfile.TemporaryDirectory()
42
  temp_filepath = os.path.join(temp_dir.name, csv_file.name)