Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -28,7 +28,7 @@ def get_text_file(text_contents):
|
|
| 28 |
temp_dir = tempfile.TemporaryDirectory() # 임시 디렉토리를 생성합니다.
|
| 29 |
temp_filepath = os.path.join(temp_dir.name, text_contents.name) # 임시 텍스트 파일 경로를 생성합니다.
|
| 30 |
with open(temp_filepath, "w", encoding="utf-8") as f: # 텍스트 파일을 쓰기 모드로 엽니다.
|
| 31 |
-
f.write(
|
| 32 |
text_loader = TextLoader(temp_filepath) # TextLoader를 사용해 텍스트 파일을 로드합니다.
|
| 33 |
text_content = text_loader.load() # 텍스트를 추출합니다.
|
| 34 |
return text_content # 추출한 텍스트를 반환합니다.
|
|
@@ -37,18 +37,15 @@ def get_csv_file(csv_datas):
|
|
| 37 |
temp_dir = tempfile.TemporaryDirectory() # 임시 디렉토리를 생성합니다.
|
| 38 |
temp_filepath = os.path.join(temp_dir.name, csv_datas.name) # 임시 CSV 파일 경로를 생성합니다.
|
| 39 |
with open(temp_filepath, "w", newline="", encoding="utf-8") as csvfile: # CSV 파일을 쓰기 모드로 엽니다.
|
| 40 |
-
|
| 41 |
-
csv_loader.load(csv_data) # CSV 데이터를 파일에 씁니다.
|
| 42 |
return temp_filepath # 생성된 임시 CSV 파일 경로를 반환합니다.
|
| 43 |
|
| 44 |
def get_json_file(json_data):
|
| 45 |
temp_dir = tempfile.TemporaryDirectory() # 임시 디렉토리를 생성합니다.
|
| 46 |
-
temp_filepath = os.path.join(temp_dir.name,
|
| 47 |
with open(temp_filepath, "w", encoding="utf-8") as jsonfile: # JSON 파일을 쓰기 모드로 엽니다.
|
| 48 |
-
|
| 49 |
-
|
| 50 |
-
return temp_filepath # 생성된 임시 JSON 파일 경로를 반환합니다
|
| 51 |
-
|
| 52 |
|
| 53 |
# 문서들을 처리하여 텍스트 청크로 나누는 함수입니다.
|
| 54 |
def get_text_chunks(documents):
|
|
|
|
| 28 |
temp_dir = tempfile.TemporaryDirectory() # 임시 디렉토리를 생성합니다.
|
| 29 |
temp_filepath = os.path.join(temp_dir.name, text_contents.name) # 임시 텍스트 파일 경로를 생성합니다.
|
| 30 |
with open(temp_filepath, "w", encoding="utf-8") as f: # 텍스트 파일을 쓰기 모드로 엽니다.
|
| 31 |
+
f.write(text_contents.getvalue()) # 텍스트 데이터를 파일에 씁니다.
|
| 32 |
text_loader = TextLoader(temp_filepath) # TextLoader를 사용해 텍스트 파일을 로드합니다.
|
| 33 |
text_content = text_loader.load() # 텍스트를 추출합니다.
|
| 34 |
return text_content # 추출한 텍스트를 반환합니다.
|
|
|
|
| 37 |
temp_dir = tempfile.TemporaryDirectory() # 임시 디렉토리를 생성합니다.
|
| 38 |
temp_filepath = os.path.join(temp_dir.name, csv_datas.name) # 임시 CSV 파일 경로를 생성합니다.
|
| 39 |
with open(temp_filepath, "w", newline="", encoding="utf-8") as csvfile: # CSV 파일을 쓰기 모드로 엽니다.
|
| 40 |
+
csvfile.write(csv_datas.getvalue()) # CSV 데이터를 파일에 씁니다.
|
|
|
|
| 41 |
return temp_filepath # 생성된 임시 CSV 파일 경로를 반환합니다.
|
| 42 |
|
| 43 |
def get_json_file(json_data):
|
| 44 |
temp_dir = tempfile.TemporaryDirectory() # 임시 디렉토리를 생성합니다.
|
| 45 |
+
temp_filepath = os.path.join(temp_dir.name, json_data.name) # 임시 JSON 파일 경로를 생성합니다.
|
| 46 |
with open(temp_filepath, "w", encoding="utf-8") as jsonfile: # JSON 파일을 쓰기 모드로 엽니다.
|
| 47 |
+
jsonfile.write(json_data.getvalue()) # JSON 데이터를 파일에 씁니다.
|
| 48 |
+
return temp_filepath # 생성된 임시 JSON 파일 경로를 반환합니다.
|
|
|
|
|
|
|
| 49 |
|
| 50 |
# 문서들을 처리하여 텍스트 청크로 나누는 함수입니다.
|
| 51 |
def get_text_chunks(documents):
|