bin20 commited on
Commit
67d8dbd
·
1 Parent(s): d4d0348

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +9 -22
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
- if json_datas is not None:
52
- with open(temp_filepath, "w", encoding="utf-8") as jsonfile: # JSON 파일을 쓰기 모드로 엽니다.
53
- jsonfile.write(json_datas.getvalue().decode('utf-8')) # JSON 데이터를 파일에 씁니다.
54
-
55
- # JSONLoader를 초기화할 때 jq_schema를 None으로 설정하여 전체 데이터를 가져옵니다.
56
- json_loader = JSONLoader(
57
- temp_filepath,
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(