sys2 commited on
Commit
632eab2
·
1 Parent(s): 79dafe9

first commit

Browse files
Files changed (1) hide show
  1. app.py +35 -23
app.py CHANGED
@@ -30,29 +30,41 @@ def get_pdf_text(pdf_docs):
30
  # 과제
31
  # 아래 텍스트 추출 함수를 작성
32
 
33
- def get_text_file(docs):
34
- text_list = []
35
- text = docs.getvalue().decode('utf-8')
36
- text_list.append(text)
37
- return text_list
38
-
39
-
40
- def get_csv_file(docs):
41
- text_list = []
42
- df = pd.read_csv(docs)
43
- for column in df.columns:
44
- text_list.extend(df[column].astype(str).tolist())
45
- return text_list
46
-
47
- def get_json_file(docs):
48
- text_list = []
49
- data = json.load(docs)
50
- if isinstance(data, list):
51
- for item in data:
52
- text_list.append(json.dumps(item))
53
- elif isinstance(data, dict):
54
- text_list.append(json.dumps(data))
55
- return text_list
 
 
 
 
 
 
 
 
 
 
 
 
56
 
57
 
58
  # 문서들을 처리하여 텍스트 청크로 나누는 함수입니다.
 
30
  # 과제
31
  # 아래 텍스트 추출 함수를 작성
32
 
33
+ def get_text_file(text_docs):
34
+ temp_dir = tempfile.TemporaryDirectory() # 임시 디렉토리를 생성합니다.
35
+ temp_filepath = os.path.join(temp_dir.name, text_docs.name) # 임시 파일 경로를 생성합니다.
36
+
37
+ with open(temp_filepath, "wb") as f: # 임시 파일을 바이너리 쓰기 모드로 엽니다.
38
+ f.write(text_docs.getvalue())
39
+
40
+ text_loader = TextLoader(temp_filepath)
41
+ text_doc = text_loader.load()
42
+ return text_doc
43
+
44
+
45
+ def get_csv_file(csv_docs):
46
+ temp_dir = tempfile.TemporaryDirectory() # 임시 디렉토리를 생성합니다.
47
+ temp_filepath = os.path.join(temp_dir.name, csv_docs.name) # 임시 파일 경로를 생성합니다.
48
+
49
+ with open(temp_filepath, "wb") as f: # 임시 파일을 바이너리 쓰기 모드로 엽니다.
50
+ f.write(csv_docs.getvalue())
51
+
52
+ text_loader = CSVLoader(temp_filepath)
53
+ text_doc = text_loader.load()
54
+ return text_doc
55
+
56
+ def get_json_file(json_docs):
57
+ temp_dir = tempfile.TemporaryDirectory() # 임시 디렉토리를 생성합니다.
58
+ temp_filepath = os.path.join(temp_dir.name, json_docs.name) # 임시 파일 경로를 생성합니다.
59
+
60
+ with open(temp_filepath, "wb") as f: # 임시 파일을 바이너리 쓰기 모드로 엽니다.
61
+ f.write(json_docs.getvalue())
62
+
63
+ json_loader = JSONLoader(temp_filepath,
64
+ jq_schema='.scans[].relationships',
65
+ text_content=False)
66
+ json_doc = json_loader.load()
67
+ return json_doc
68
 
69
 
70
  # 문서들을 처리하여 텍스트 청크로 나누는 함수입니다.