Spaces:
Runtime error
Runtime error
Refactor : jsonLoader 재구성 완료
Browse files
app.py
CHANGED
|
@@ -28,7 +28,7 @@ def get_pdf_text(pdf_docs):
|
|
| 28 |
print(pdf_doc)
|
| 29 |
return pdf_doc # 추출한 텍스트를 반환합니다.
|
| 30 |
|
| 31 |
-
|
| 32 |
# 아래 텍스트 추출 함수를 작성
|
| 33 |
def get_text_file(text_docs):
|
| 34 |
temp_dir = tempfile.TemporaryDirectory() # 임시 디렉토리를 생성합니다.
|
|
@@ -39,8 +39,6 @@ def get_text_file(text_docs):
|
|
| 39 |
text_doc = text_loader.load() # 텍스트를 추출합니다.
|
| 40 |
return text_doc # 추출한 텍스트를 반환합니다.
|
| 41 |
|
| 42 |
-
|
| 43 |
-
|
| 44 |
def get_csv_file(csv_docs):
|
| 45 |
temp_dir = tempfile.TemporaryDirectory() # 임시 디렉토리를 생성합니다.
|
| 46 |
temp_filepath = os.path.join(temp_dir.name, csv_docs.name) # 임시 파일 경로를 생성합니다.
|
|
@@ -55,7 +53,7 @@ def get_json_file(json_docs):
|
|
| 55 |
temp_filepath = os.path.join(temp_dir.name, json_docs.name) # 임시 파일 경로를 생성합니다.
|
| 56 |
with open(temp_filepath, "wb") as f: # 임시 파일을 바이너리 쓰기 모드로 엽니다.
|
| 57 |
f.write(json_docs.getvalue()) # PDF 문서의 내용을 임시 파일에 씁니다.
|
| 58 |
-
json_loader = JSONLoader(temp_filepath) # PyPDFLoader를 사용해 PDF를 로드합니다.
|
| 59 |
json_doc = json_loader.load() # 텍스트를 추출합니다.
|
| 60 |
return json_doc # 추출한 텍스트를 반환합니다.
|
| 61 |
|
|
|
|
| 28 |
print(pdf_doc)
|
| 29 |
return pdf_doc # 추출한 텍스트를 반환합니다.
|
| 30 |
|
| 31 |
+
|
| 32 |
# 아래 텍스트 추출 함수를 작성
|
| 33 |
def get_text_file(text_docs):
|
| 34 |
temp_dir = tempfile.TemporaryDirectory() # 임시 디렉토리를 생성합니다.
|
|
|
|
| 39 |
text_doc = text_loader.load() # 텍스트를 추출합니다.
|
| 40 |
return text_doc # 추출한 텍스트를 반환합니다.
|
| 41 |
|
|
|
|
|
|
|
| 42 |
def get_csv_file(csv_docs):
|
| 43 |
temp_dir = tempfile.TemporaryDirectory() # 임시 디렉토리를 생성합니다.
|
| 44 |
temp_filepath = os.path.join(temp_dir.name, csv_docs.name) # 임시 파일 경로를 생성합니다.
|
|
|
|
| 53 |
temp_filepath = os.path.join(temp_dir.name, json_docs.name) # 임시 파일 경로를 생성합니다.
|
| 54 |
with open(temp_filepath, "wb") as f: # 임시 파일을 바이너리 쓰기 모드로 엽니다.
|
| 55 |
f.write(json_docs.getvalue()) # PDF 문서의 내용을 임시 파일에 씁니다.
|
| 56 |
+
json_loader = JSONLoader(temp_filepath, jq_schema='.messages[].content', text_content = False) # PyPDFLoader를 사용해 PDF를 로드합니다.
|
| 57 |
json_doc = json_loader.load() # 텍스트를 추출합니다.
|
| 58 |
return json_doc # 추출한 텍스트를 반환합니다.
|
| 59 |
|