first commit
Browse files
app.py
CHANGED
@@ -30,29 +30,41 @@ def get_pdf_text(pdf_docs):
|
|
30 |
# 과제
|
31 |
# 아래 텍스트 추출 함수를 작성
|
32 |
|
33 |
-
def get_text_file(
|
34 |
-
|
35 |
-
|
36 |
-
|
37 |
-
|
38 |
-
|
39 |
-
|
40 |
-
|
41 |
-
|
42 |
-
|
43 |
-
|
44 |
-
|
45 |
-
|
46 |
-
|
47 |
-
|
48 |
-
|
49 |
-
|
50 |
-
|
51 |
-
|
52 |
-
|
53 |
-
|
54 |
-
|
55 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
56 |
|
57 |
|
58 |
# 문서들을 처리하여 텍스트 청크로 나누는 함수입니다.
|
|
|
30 |
# 과제
|
31 |
# 아래 텍스트 추출 함수를 작성
|
32 |
|
33 |
+
def get_text_file(text_docs):
|
34 |
+
temp_dir = tempfile.TemporaryDirectory() # 임시 디렉토리를 생성합니다.
|
35 |
+
temp_filepath = os.path.join(temp_dir.name, text_docs.name) # 임시 파일 경로를 생성합니다.
|
36 |
+
|
37 |
+
with open(temp_filepath, "wb") as f: # 임시 파일을 바이너리 쓰기 모드로 엽니다.
|
38 |
+
f.write(text_docs.getvalue())
|
39 |
+
|
40 |
+
text_loader = TextLoader(temp_filepath)
|
41 |
+
text_doc = text_loader.load()
|
42 |
+
return text_doc
|
43 |
+
|
44 |
+
|
45 |
+
def get_csv_file(csv_docs):
|
46 |
+
temp_dir = tempfile.TemporaryDirectory() # 임시 디렉토리를 생성합니다.
|
47 |
+
temp_filepath = os.path.join(temp_dir.name, csv_docs.name) # 임시 파일 경로를 생성합니다.
|
48 |
+
|
49 |
+
with open(temp_filepath, "wb") as f: # 임시 파일을 바이너리 쓰기 모드로 엽니다.
|
50 |
+
f.write(csv_docs.getvalue())
|
51 |
+
|
52 |
+
text_loader = CSVLoader(temp_filepath)
|
53 |
+
text_doc = text_loader.load()
|
54 |
+
return text_doc
|
55 |
+
|
56 |
+
def get_json_file(json_docs):
|
57 |
+
temp_dir = tempfile.TemporaryDirectory() # 임시 디렉토리를 생성합니다.
|
58 |
+
temp_filepath = os.path.join(temp_dir.name, json_docs.name) # 임시 파일 경로를 생성합니다.
|
59 |
+
|
60 |
+
with open(temp_filepath, "wb") as f: # 임시 파일을 바이너리 쓰기 모드로 엽니다.
|
61 |
+
f.write(json_docs.getvalue())
|
62 |
+
|
63 |
+
json_loader = JSONLoader(temp_filepath,
|
64 |
+
jq_schema='.scans[].relationships',
|
65 |
+
text_content=False)
|
66 |
+
json_doc = json_loader.load()
|
67 |
+
return json_doc
|
68 |
|
69 |
|
70 |
# 문서들을 처리하여 텍스트 청크로 나누는 함수입니다.
|