Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -46,28 +46,15 @@ def get_csv_text(csv_file):
|
|
| 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 |
-
|
| 50 |
-
|
| 51 |
-
|
| 52 |
-
|
| 53 |
-
|
| 54 |
-
|
| 55 |
-
|
| 56 |
-
|
| 57 |
-
|
| 58 |
-
jq_schema=None,
|
| 59 |
-
text_content=False
|
| 60 |
-
)
|
| 61 |
-
|
| 62 |
-
# JSON 데이터를 로드합니다.
|
| 63 |
-
json_data = json_loader.load()
|
| 64 |
-
return json_data
|
| 65 |
-
else:
|
| 66 |
-
# 만약 json_datas가 None이면 아무것도 반환하지 않습니다.
|
| 67 |
-
return None
|
| 68 |
-
|
| 69 |
-
|
| 70 |
-
|
| 71 |
# 문서들을 처리하여 텍스트 청크로 나누는 함수입니다.
|
| 72 |
def get_text_chunks(documents):
|
| 73 |
text_splitter = RecursiveCharacterTextSplitter(
|
|
|
|
| 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().decode('utf-8')) # 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):
|
| 60 |
text_splitter = RecursiveCharacterTextSplitter(
|