Update app.py
Browse files
app.py
CHANGED
@@ -32,17 +32,29 @@ def get_text_file(text_docs):
|
|
32 |
temp_dir1 = tempfile.TemporaryDirectory() # 임시 디렉토리를 생성합니다.
|
33 |
temp_filepath1 = os.path.join(temp_dir1.name, text_docs.name) # 임시 파일 경로를 생성합니다.
|
34 |
with open(temp_filepath1, "wb") as f: # 임시 파일을 바이너리 쓰기 모드로 엽니다.
|
35 |
-
f.write(text_docs.getvalue()) #
|
36 |
-
text_loader = TextLoader(temp_filepath1) #
|
37 |
text_doc = text_loader.load() # 텍스트를 추출합니다.
|
38 |
return text_doc # 추출한 텍스트를 반환합니다.
|
39 |
|
40 |
|
41 |
def get_csv_file(docs):
|
42 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
43 |
|
44 |
def get_json_file(docs):
|
45 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
46 |
|
47 |
|
48 |
# 문서들을 처리하여 텍스트 청크로 나누는 함수입니다.
|
|
|
32 |
temp_dir1 = tempfile.TemporaryDirectory() # 임시 디렉토리를 생성합니다.
|
33 |
temp_filepath1 = os.path.join(temp_dir1.name, text_docs.name) # 임시 파일 경로를 생성합니다.
|
34 |
with open(temp_filepath1, "wb") as f: # 임시 파일을 바이너리 쓰기 모드로 엽니다.
|
35 |
+
f.write(text_docs.getvalue()) # TXT 문서의 내용을 임시 파일에 씁니다.
|
36 |
+
text_loader = TextLoader(temp_filepath1) # TextFLoader를 사용해 PDF를 로드합니다.
|
37 |
text_doc = text_loader.load() # 텍스트를 추출합니다.
|
38 |
return text_doc # 추출한 텍스트를 반환합니다.
|
39 |
|
40 |
|
41 |
def get_csv_file(docs):
|
42 |
+
temp_dir2 = tempfile.TemporaryDirectory() # 임시 디렉토리를 생성합니다.
|
43 |
+
temp_filepath2 = os.path.join(temp_dir2.name, csv_docs.name) # 임시 파일 경로를 생성합니다.
|
44 |
+
with open(temp_filepath2, "wb") as f: # 임시 파일을 바이너리 쓰기 모드로 엽니다.
|
45 |
+
f.write(csv_docs.getvalue()) # CSV 문서의 내용을 임시 파일에 씁니다.
|
46 |
+
csv_loader = CSVLoader(temp_filepath2) # CSVLoader를 사용해 PDF를 로드합니다.
|
47 |
+
csv_doc = csv_loader.load() # 텍스트를 추출합니다.
|
48 |
+
return csv_doc # 추출한 텍스트를 반환합니다.
|
49 |
|
50 |
def get_json_file(docs):
|
51 |
+
temp_dir3 = tempfile.TemporaryDirectory() # 임시 디렉토리를 생성합니다.
|
52 |
+
temp_filepath3 = os.path.join(temp_dir3.name, json_docs.name) # 임시 파일 경로를 생성합니다.
|
53 |
+
with open(temp_filepath3, "wb") as f: # 임시 파일을 바이너리 쓰기 모드로 엽니다.
|
54 |
+
f.write(json_docs.getvalue()) # JSON 문서의 내용을 임시 파일에 씁니다.
|
55 |
+
json_loader = JSONLoader(temp_filepath3) # JSONLoader를 사용해 PDF를 로드합니다.
|
56 |
+
json_doc = json_loader.load() # 텍스트를 추출합니다.
|
57 |
+
return json_doc # 추출한 텍스트를 반환합니다.
|
58 |
|
59 |
|
60 |
# 문서들을 처리하여 텍스트 청크로 나누는 함수입니다.
|