Daoneeee commited on
Commit
ab8aa88
·
1 Parent(s): 0427804

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +30 -21
app.py CHANGED
@@ -15,6 +15,15 @@ import tempfile # 임시 파일을 생성하기 위한 라이브러리입니다
15
  import os
16
 
17
 
 
 
 
 
 
 
 
 
 
18
  # PDF 문서로부터 텍스트를 추출하는 함수입니다.
19
  def get_pdf_text(pdf_docs):
20
  temp_dir = tempfile.TemporaryDirectory() # 임시 디렉토리를 생성합니다.
@@ -30,31 +39,31 @@ def get_pdf_text(pdf_docs):
30
  # 아래 텍스트 추출 함수를 작성
31
 
32
  def get_text_file(text_docs):
33
- temp_dir = tempfile.TemporaryDirectory() # 임시 디렉토리를 생성합니다.
34
- temp_filepath = os.path.join(temp_dir.name, text_docs.name) # 임시 파일 경로를 생성합니다.
35
- with open(temp_filepath, "wb") as f: # 임시 파일을 바이너리 쓰기 모드로 엽니다.
36
- f.write(text_docs.getvalue()) # PDF 문서의 내용을 임시 파일에 씁니다.
37
- text_loader = TextLoader(temp_filepath) # PyPDFLoader를 사용해 PDF를 로드합니다.
38
- text_doc = text_loader.load() # 텍스트를 추출합니다.
39
- return text_doc # 추출한 텍스트를 반환합니다.
40
 
41
  def get_csv_file(csv_docs):
42
- temp_dir = tempfile.TemporaryDirectory() # 임시 디렉토리를 생성합니다.
43
- temp_filepath = os.path.join(temp_dir.name, csv_docs.name) # 임시 파일 경로를 생성합니다.
44
- with open(temp_filepath, "wb") as f: # 임시 파일을 바이너리 쓰기 모드로 엽니다.
45
- f.write(csv_docs.getvalue()) # PDF 문서의 내용을 임시 파일에 씁니다.
46
- csv_loader = CSVLoader(temp_filepath) # PyPDFLoader를 사용해 PDF를 로드합니다.
47
- csv_doc = csv_loader.load() # 텍스트를 추출합니다.
48
- return csv_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()) # PDF 문서의 내용을 임시 파일에 씁니다.
55
- json_loader = JSONLoader(temp_filepath) # PyPDFLoader를 사용해 PDF를 로드합니다.
56
- json_doc = json_loader.load() # 텍스트를 추출합니다.
57
- return json_doc # 추출한 텍스트를 반환합니다.
58
 
59
 
60
  # 문서들을 처리하여 텍스트 청크로 나누는 함수입니다.
 
15
  import os
16
 
17
 
18
+ import json
19
+ from pathlib import Path
20
+
21
+
22
+ file_path='./example_data/facebook_chat.json'
23
+ data = json.loads(Path(file_path).read_text())
24
+
25
+
26
+
27
  # PDF 문서로부터 텍스트를 추출하는 함수입니다.
28
  def get_pdf_text(pdf_docs):
29
  temp_dir = tempfile.TemporaryDirectory() # 임시 디렉토리를 생성합니다.
 
39
  # 아래 텍스트 추출 함수를 작성
40
 
41
  def get_text_file(text_docs):
42
+ temp_dir = tempfile.TemporaryDirectory()
43
+ temp_filepath = os.path.join(temp_dir.name, text_docs.name)
44
+ with open(temp_filepath, "wb") as f:
45
+ f.write(text_docs.getvalue())
46
+ text_loader = TextLoader(temp_filepath)
47
+ text_doc = text_loader.load()
48
+ return text_doc
49
 
50
  def get_csv_file(csv_docs):
51
+ temp_dir = tempfile.TemporaryDirectory()
52
+ temp_filepath = os.path.join(temp_dir.name, csv_docs.name)
53
+ with open(temp_filepath, "wb") as f:
54
+ f.write(csv_docs.getvalue())
55
+ csv_loader = CSVLoader(temp_filepath)
56
+ csv_doc = csv_loader.load()
57
+ return csv_doc
58
 
59
  def get_json_file(json_docs):
60
+ temp_dir = tempfile.TemporaryDirectory()
61
+ temp_filepath = os.path.join(temp_dir.name, json_docs.name)
62
+ with open(temp_filepath, "wb") as f:
63
+ f.write(json_docs.getvalue())
64
+ json_loader = JSONLoader(temp_filepath)
65
+ json_doc = json_loader.load()
66
+ return json_doc
67
 
68
 
69
  # 문서들을 처리하여 텍스트 청크로 나누는 함수입니다.