OhST commited on
Commit
6af5a93
1 Parent(s): 1ab6872

text랑 csv 추출 함수 작성함

Browse files
Files changed (1) hide show
  1. app.py +21 -3
app.py CHANGED
@@ -29,10 +29,28 @@ def get_pdf_text(pdf_docs):
29
  # 아래 텍스트 추출 함수를 작성
30
 
31
  def get_text_file(txt_docs):
32
- pass
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
33
 
34
- def get_csv_file(docs):
35
- pass
36
 
37
  def get_json_file(json_docs):
38
  temp_dir = tempfile.TemporaryDirectory()
 
29
  # 아래 텍스트 추출 함수를 작성
30
 
31
  def get_text_file(txt_docs):
32
+ temp_dir = tempfile.TemporaryDirectory() # 임시 디렉토리를 생성합니다.
33
+ temp_filepath = os.path.join(temp_dir.name, txt_docs.name) # 임시 파일 경로를 생성합니다.
34
+ with open(temp_filepath, "wb") as f: # 임시 파일을 바이너리 쓰기 모드로 엽니다.
35
+ f.write(txt_docs.getvalue()) # txt 문서의 내용을 임시 파일에 씁니다.
36
+ txt_loader = TextLoader(temp_filepath)
37
+ txt_doc = txt_loader.load()
38
+ return txt_doc
39
+
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()) # csv 문서의 내용을 임시 파일에 씁니다.
46
+ csv_loader = CSVLoader(file_path=temp_filepath, csv_args={
47
+ 'delimiter': ',',
48
+ 'quotechar': '',
49
+ 'fieldnames':['PassengerId', 'Survived', 'Pclass', 'Name', 'Sex',
50
+ 'Age', 'Sibsp', 'Parch', 'Ticket', 'Fare', 'Cabin', 'Embarked']})
51
+ csv_doc = csv_loader.load()
52
+ return csv_doc
53
 
 
 
54
 
55
  def get_json_file(json_docs):
56
  temp_dir = tempfile.TemporaryDirectory()