HanKang commited on
Commit
ccaf37b
·
1 Parent(s): 897ec15

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +24 -6
app.py CHANGED
@@ -28,15 +28,33 @@ def get_pdf_text(pdf_docs):
28
  # 과제
29
  # 아래 텍스트 추출 함수를 작성
30
 
31
- def get_text_file(docs):
32
- pass
 
 
 
 
 
 
33
 
34
 
35
- def get_csv_file(docs):
36
- pass
 
 
 
 
 
 
37
 
38
- def get_json_file(docs):
39
- pass
 
 
 
 
 
 
40
 
41
 
42
  # 문서들을 처리하여 텍스트 청크로 나누는 함수입니다.
 
28
  # 과제
29
  # 아래 텍스트 추출 함수를 작성
30
 
31
+ def get_text_file(text_docs):
32
+ temp_dir = tempfile.TemporaryDirectory() # 임시 디렉토리를 생성합니다.
33
+ temp_filepath = os.path.join(temp_dir.name, text_docs.name) # 임시 파일 경로를 생성합니다.
34
+ with open(temp_filepath, "wb") as f: # 임시 파일을 바이너리 쓰기 모드로 엽니다.
35
+ f.write(text_docs.getvalue()) # TEXT 문서의 내용을 임시 파일에 씁니다.
36
+ text_loader = TextLoader(temp_filepath) # TextLoader를 사용해 Text를 로드합니다.
37
+ text_doc = text_loader.load() # 텍스트를 추출합니다.
38
+ return text_doc # 추출한 텍스트를 반환합니다.
39
 
40
 
41
+ def get_csv_file(csv_docs):
42
+ temp_dir = tempfile.TemporaryDirectory() # 임시 디렉토리를 생성합니다.
43
+ temp_filepath = os.path.join(temp_dir.name, cvs_docs.name) # 임시 파일 경로를 생성합니다.
44
+ with open(temp_filepath, "wb") as f: # 임시 파일을 바이너리 쓰기 모드로 엽니다.
45
+ f.write(cvs_docs.getvalue()) # CVS 문서의 내용을 임시 파일에 씁니다.
46
+ cvs_loader = CVSLoader(temp_filepath, source_column="Team") # CVSLoader를 사용해 CVS를 로드합니다.
47
+ cvs_doc = cvs_loader.load() # 텍스트를 추출합니다.
48
+ return cvs_doc # 추출한 텍스트를 반환합니다.
49
 
50
+ def get_json_file(json_docs):
51
+ temp_dir = tempfile.TemporaryDirectory() # 임시 디렉토리를 생성합니다.
52
+ temp_filepath = os.path.join(temp_dir.name, json_docs.name) # 임시 파일 경로를 생성합니다.
53
+ with open(temp_filepath, "wb") as f: # 임시 파일을 바이너리 쓰기 모드로 엽니다.
54
+ f.write(json_docs.getvalue()) # JSON 문서의 내용을 임시 파일에 씁니다.
55
+ json_loader = JSONLoader(temp_filepath, jq_schema='.messages[].content', text_content=False) # JSONLoader를 사용해 JSON을 로드합니다.
56
+ json_doc = json_loader.load() # 텍스트를 추출합니다.
57
+ return json_doc # 추출한 텍스트를 반환합니다.
58
 
59
 
60
  # 문서들을 처리하여 텍스트 청크로 나누는 함수입니다.