Spaces:
Sleeping
Sleeping
Update app.py
Browse files
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, "
|
31 |
-
|
|
|
|
|
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)
|