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