Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -24,32 +24,36 @@ def get_pdf_text(pdf_docs):
|
|
24 |
|
25 |
# 과제
|
26 |
# 아래 텍스트 추출 함수를 작성
|
27 |
-
def get_text_file(
|
28 |
-
temp_dir = tempfile.TemporaryDirectory()
|
29 |
-
temp_filepath = os.path.join(temp_dir.name,
|
30 |
-
with open(temp_filepath, "w", encoding="utf-8") as
|
31 |
-
|
32 |
-
text_loader = TextLoader(temp_filepath)
|
33 |
-
|
34 |
-
return
|
35 |
-
|
36 |
-
def
|
37 |
-
temp_dir = tempfile.TemporaryDirectory()
|
38 |
-
temp_filepath = os.path.join(temp_dir.name,
|
39 |
-
with open(temp_filepath, "w",
|
40 |
-
csvfile.write(
|
41 |
-
csv_loader = CSVLoader(temp_filepath)
|
42 |
csv_data = csv_loader.load()
|
43 |
-
|
|
|
44 |
|
45 |
def get_json_file(json_datas):
|
46 |
temp_dir = tempfile.TemporaryDirectory() # 임시 디렉토리를 생성합니다.
|
47 |
temp_filepath = os.path.join(temp_dir.name, json_datas.name) # 임시 JSON 파일 경로를 생성합니다.
|
48 |
with open(temp_filepath, "w", encoding="utf-8") as jsonfile: # JSON 파일을 쓰기 모드로 엽니다.
|
49 |
jsonfile.write(json_datas.getvalue()) # JSON 데이터를 파일에 씁니다.
|
50 |
-
json_loader = JSONLoader(
|
|
|
|
|
|
|
51 |
json_data = json_loader.load()
|
52 |
-
return json_data
|
53 |
|
54 |
# 문서들을 처리하여 텍스트 청크로 나누는 함수입니다.
|
55 |
def get_text_chunks(documents):
|
|
|
24 |
|
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, "w", encoding="utf-8") as textfile:
|
31 |
+
textfile.write(text_data.getvalue())
|
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)
|
39 |
+
with open(temp_filepath, "w", encoding="utf-8") as csvfile:
|
40 |
+
csvfile.write(csv_file.getvalue())
|
41 |
+
csv_loader = CSVLoader(temp_filepath, text_column='text_column_name')
|
42 |
csv_data = csv_loader.load()
|
43 |
+
text_from_csv = '\n'.join(csv_data['text_column_name']) if 'text_column_name' in csv_data else ''
|
44 |
+
return text_from_csv
|
45 |
|
46 |
def get_json_file(json_datas):
|
47 |
temp_dir = tempfile.TemporaryDirectory() # 임시 디렉토리를 생성합니다.
|
48 |
temp_filepath = os.path.join(temp_dir.name, json_datas.name) # 임시 JSON 파일 경로를 생성합니다.
|
49 |
with open(temp_filepath, "w", encoding="utf-8") as jsonfile: # JSON 파일을 쓰기 모드로 엽니다.
|
50 |
jsonfile.write(json_datas.getvalue()) # JSON 데이터를 파일에 씁니다.
|
51 |
+
json_loader = JSONLoader(
|
52 |
+
temp_filepath,
|
53 |
+
jq_schema='messages[].content',
|
54 |
+
text_content=False)
|
55 |
json_data = json_loader.load()
|
56 |
+
return json_data
|
57 |
|
58 |
# 문서들을 처리하여 텍스트 청크로 나누는 함수입니다.
|
59 |
def get_text_chunks(documents):
|