sujeongim0402@gmail.com commited on
Commit
b4b9a43
β€’
1 Parent(s): 5d88956

edit codes

Browse files
Files changed (1) hide show
  1. app.py +10 -27
app.py CHANGED
@@ -30,24 +30,10 @@ def get_pdf_text(pdf_docs):
30
  # 과제
31
  # μ•„λž˜ ν…μŠ€νŠΈ μΆ”μΆœ ν•¨μˆ˜λ₯Ό μž‘μ„±
32
 
33
- # def get_text_file(docs):
34
- # temp_dir2 = tempfile.TemporaryDirectory() # μž„μ‹œ 디렉토리λ₯Ό μƒμ„±ν•©λ‹ˆλ‹€.
35
- # temp_filepath2 = os.path.join(temp_dir2.name, docs.name) # μž„μ‹œ 파일 경둜λ₯Ό μƒμ„±ν•©λ‹ˆλ‹€.
36
- # with open(temp_filepath2, "wb") as f: # μž„μ‹œ νŒŒμΌμ„ λ°”μ΄λ„ˆλ¦¬ μ“°κΈ° λͺ¨λ“œλ‘œ μ—½λ‹ˆλ‹€.
37
- # f.write(docs.getvalue()) # TXT λ¬Έμ„œμ˜ λ‚΄μš©μ„ μž„μ‹œ νŒŒμΌμ— μ”λ‹ˆλ‹€.
38
- # text_loader = TextLoader(
39
- # file_path=temp_filepath2,
40
- # txt_schema='',
41
- # text_content=False
42
- # ) # Use your specific text loader here.
43
- # text_data = text_loader.load() # Extract text using the loader.
44
- # return text_data # μΆ”μΆœν•œ ν…μŠ€νŠΈλ₯Ό λ°˜ν™˜ν•©λ‹ˆλ‹€.
45
  def get_text_file(docs):
46
  temp_dir2 = tempfile.TemporaryDirectory() # μž„μ‹œ 디렉토리λ₯Ό μƒμ„±ν•©λ‹ˆλ‹€.
47
  temp_filepath2 = os.path.join(temp_dir2.name, docs.name) # μž„μ‹œ 파일 경둜λ₯Ό μƒμ„±ν•©λ‹ˆλ‹€.
48
- txt_loader = TextLoader(
49
- file_path=temp_filepath2
50
- )
51
  txt_data = txt_loader.load()
52
  return txt_data
53
 
@@ -56,18 +42,15 @@ def get_csv_file(docs):
56
  temp_filepath3 = os.path.join(temp_dir3.name, docs.name)
57
  with open(temp_filepath3, "wb") as f:
58
  f.write(docs.getvalue())
59
-
60
- # csv_data = []
61
- # with open(temp_filepath3, "r") as csv_file:
62
- # csv_reader = csv.reader(csv_file)
63
- # for row in csv_reader:
64
- # csv_data.append(row)
65
- # csv_loader = CSVLoader(
66
- # file_path=temp_filepath3,
67
- # cs_schema='.data[].address',
68
- # text_content=False
69
- # )
70
- # csv_data = csv_loader.load()
71
  return csv_data
72
 
73
  def get_json_file(docs):
 
30
  # 과제
31
  # μ•„λž˜ ν…μŠ€νŠΈ μΆ”μΆœ ν•¨μˆ˜λ₯Ό μž‘μ„±
32
 
 
 
 
 
 
 
 
 
 
 
 
 
33
  def get_text_file(docs):
34
  temp_dir2 = tempfile.TemporaryDirectory() # μž„μ‹œ 디렉토리λ₯Ό μƒμ„±ν•©λ‹ˆλ‹€.
35
  temp_filepath2 = os.path.join(temp_dir2.name, docs.name) # μž„μ‹œ 파일 경둜λ₯Ό μƒμ„±ν•©λ‹ˆλ‹€.
36
+ txt_loader = TextLoader(temp_filepath2)
 
 
37
  txt_data = txt_loader.load()
38
  return txt_data
39
 
 
42
  temp_filepath3 = os.path.join(temp_dir3.name, docs.name)
43
  with open(temp_filepath3, "wb") as f:
44
  f.write(docs.getvalue())
45
+ csv_loader = CSVLoader(
46
+ file_path=temp_filepath3,
47
+ csv_args={
48
+ "delimiter": ",",
49
+ "quotechar": '"',
50
+ "fieldnames": ["name", "school", "address", "phone"],
51
+ },
52
+ )
53
+ csv_data = csv_loader.load()
 
 
 
54
  return csv_data
55
 
56
  def get_json_file(docs):