Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -15,6 +15,15 @@ import tempfile # 임시 파일을 생성하기 위한 라이브러리입니다
|
|
15 |
import os
|
16 |
|
17 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
18 |
# PDF 문서로부터 텍스트를 추출하는 함수입니다.
|
19 |
def get_pdf_text(pdf_docs):
|
20 |
temp_dir = tempfile.TemporaryDirectory() # 임시 디렉토리를 생성합니다.
|
@@ -30,31 +39,31 @@ def get_pdf_text(pdf_docs):
|
|
30 |
# 아래 텍스트 추출 함수를 작성
|
31 |
|
32 |
def get_text_file(text_docs):
|
33 |
-
temp_dir = tempfile.TemporaryDirectory()
|
34 |
-
temp_filepath = os.path.join(temp_dir.name, text_docs.name)
|
35 |
-
with open(temp_filepath, "wb") as f:
|
36 |
-
f.write(text_docs.getvalue())
|
37 |
-
text_loader = TextLoader(temp_filepath)
|
38 |
-
text_doc = text_loader.load()
|
39 |
-
return text_doc
|
40 |
|
41 |
def get_csv_file(csv_docs):
|
42 |
-
temp_dir = tempfile.TemporaryDirectory()
|
43 |
-
temp_filepath = os.path.join(temp_dir.name, csv_docs.name)
|
44 |
-
with open(temp_filepath, "wb") as f:
|
45 |
-
f.write(csv_docs.getvalue())
|
46 |
-
csv_loader = CSVLoader(temp_filepath)
|
47 |
-
csv_doc = csv_loader.load()
|
48 |
-
return csv_doc
|
49 |
|
50 |
def get_json_file(json_docs):
|
51 |
-
temp_dir = tempfile.TemporaryDirectory()
|
52 |
-
temp_filepath = os.path.join(temp_dir.name, json_docs.name)
|
53 |
-
with open(temp_filepath, "wb") as f:
|
54 |
-
f.write(json_docs.getvalue())
|
55 |
-
json_loader = JSONLoader(temp_filepath)
|
56 |
-
json_doc = json_loader.load()
|
57 |
-
return json_doc
|
58 |
|
59 |
|
60 |
# 문서들을 처리하여 텍스트 청크로 나누는 함수입니다.
|
|
|
15 |
import os
|
16 |
|
17 |
|
18 |
+
import json
|
19 |
+
from pathlib import Path
|
20 |
+
|
21 |
+
|
22 |
+
file_path='./example_data/facebook_chat.json'
|
23 |
+
data = json.loads(Path(file_path).read_text())
|
24 |
+
|
25 |
+
|
26 |
+
|
27 |
# PDF 문서로부터 텍스트를 추출하는 함수입니다.
|
28 |
def get_pdf_text(pdf_docs):
|
29 |
temp_dir = tempfile.TemporaryDirectory() # 임시 디렉토리를 생성합니다.
|
|
|
39 |
# 아래 텍스트 추출 함수를 작성
|
40 |
|
41 |
def get_text_file(text_docs):
|
42 |
+
temp_dir = tempfile.TemporaryDirectory()
|
43 |
+
temp_filepath = os.path.join(temp_dir.name, text_docs.name)
|
44 |
+
with open(temp_filepath, "wb") as f:
|
45 |
+
f.write(text_docs.getvalue())
|
46 |
+
text_loader = TextLoader(temp_filepath)
|
47 |
+
text_doc = text_loader.load()
|
48 |
+
return text_doc
|
49 |
|
50 |
def get_csv_file(csv_docs):
|
51 |
+
temp_dir = tempfile.TemporaryDirectory()
|
52 |
+
temp_filepath = os.path.join(temp_dir.name, csv_docs.name)
|
53 |
+
with open(temp_filepath, "wb") as f:
|
54 |
+
f.write(csv_docs.getvalue())
|
55 |
+
csv_loader = CSVLoader(temp_filepath)
|
56 |
+
csv_doc = csv_loader.load()
|
57 |
+
return csv_doc
|
58 |
|
59 |
def get_json_file(json_docs):
|
60 |
+
temp_dir = tempfile.TemporaryDirectory()
|
61 |
+
temp_filepath = os.path.join(temp_dir.name, json_docs.name)
|
62 |
+
with open(temp_filepath, "wb") as f:
|
63 |
+
f.write(json_docs.getvalue())
|
64 |
+
json_loader = JSONLoader(temp_filepath)
|
65 |
+
json_doc = json_loader.load()
|
66 |
+
return json_doc
|
67 |
|
68 |
|
69 |
# 문서들을 처리하여 텍스트 청크로 나누는 함수입니다.
|