Daoneeee commited on
Commit
08b8cb0
·
1 Parent(s): 3337f98

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +30 -4
app.py CHANGED
@@ -29,14 +29,40 @@ def get_pdf_text(pdf_docs):
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
  # 문서들을 처리하여 텍스트 청크로 나누는 함수입니다.
 
29
  # 아래 텍스트 추출 함수를 작성
30
 
31
  def get_text_file(docs):
32
+ # 텍스트 파일의 경우, 내용을 바로 읽어옵니다.
33
+ text_content = docs.getvalue().decode("utf-8") # UTF-8 인코딩을 기준으로 디코딩합니다.
34
+ return [text_content]
35
 
36
  def get_csv_file(docs):
37
+ # CSV 파일의 경우, 각 행 또는 열에서 텍스트를 추출합니다.
38
+ import pandas as pd
39
+ csv_content = docs.getvalue().decode("utf-8") # 바이트를 문자열로 디코딩합니다.
40
+ csv_data = pd.read_csv(pd.compat.StringIO(csv_content)) # Pandas를 사용하여 CSV를 읽어옵니다.
41
+ text_list = []
42
+
43
+ # 필요한 대로 각 열 또는 행에서 텍스트를 추출합니다.
44
+ for column in csv_data.columns:
45
+ text_list.extend(csv_data[column].astype(str).tolist())
46
+
47
+ return text_list
48
 
49
  def get_json_file(docs):
50
+ # JSON 파일의 경우, 특정 키 또는 값에서 텍스트를 추출합니다.
51
+ import json
52
+ json_content = docs.getvalue().decode("utf-8") # 바이트를 문자열로 디코딩합니다.
53
+ json_data = json.loads(json_content)
54
+
55
+ # 필요한 대로 JSON 키 또는 값에서 텍스트를 추출합니다.
56
+ text_list = []
57
+ for key, value in json_data.items():
58
+ if isinstance(value, str):
59
+ text_list.append(value)
60
+ elif isinstance(value, list):
61
+ text_list.extend(value)
62
+ elif isinstance(value, dict):
63
+ text_list.extend(value.values())
64
+
65
+ return text_list
66
 
67
 
68
  # 문서들을 처리하여 텍스트 청크로 나누는 함수입니다.