hula0627 commited on
Commit
a865033
Β·
1 Parent(s): 9952999

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +22 -4
app.py CHANGED
@@ -25,13 +25,31 @@ def get_pdf_text(pdf_docs):
25
  # 과제
26
  # μ•„λž˜ ν…μŠ€νŠΈ μΆ”μΆœ ν•¨μˆ˜λ₯Ό μž‘μ„±
27
  def get_text_file(docs):
28
- pass
 
 
 
 
 
 
29
 
30
- def get_csv_file(docs):
31
- pass
 
 
 
 
 
 
32
 
33
  def get_json_file(docs):
34
- pass
 
 
 
 
 
 
35
 
36
 
37
  # λ¬Έμ„œλ“€μ„ μ²˜λ¦¬ν•˜μ—¬ ν…μŠ€νŠΈ 청크둜 λ‚˜λˆ„λŠ” ν•¨μˆ˜μž…λ‹ˆλ‹€.
 
25
  # 과제
26
  # μ•„λž˜ ν…μŠ€νŠΈ μΆ”μΆœ ν•¨μˆ˜λ₯Ό μž‘μ„±
27
  def get_text_file(docs):
28
+ temp_dir = tempfile.TemporaryDirectory()
29
+ temp_filepath = os.path.join(temp_dir.name, txt_docs.name)
30
+ with open(temp_filepath, "wb") as f:
31
+ f.write(txt_docs.getvalue())
32
+ txt_loader = TextLoader(temp_filepath)
33
+ txt_doc = txt_loader.load()
34
+ return txt_doc
35
 
36
+ def get_csv_file(csv_docs):
37
+ temp_dir = tempfile.TemporaryDirectory()
38
+ temp_filepath = os.path.join(temp_dir.name, csv_docs.name)
39
+ with open(temp_filepath, "wb") as f:
40
+ f.write(csv_docs.getvalue())
41
+ csv_loader = CSVLoader(file_path=temp_filepath)
42
+ csv_doc = csv_loader.load()
43
+ return csv_doc
44
 
45
  def get_json_file(docs):
46
+ temp_dir = tempfile.TemporaryDirectory()
47
+ temp_filepath = os.path.join(temp_dir.name, json_docs.name)
48
+ with open(temp_filepath, "wb") as f:
49
+ f.write(json_docs.getvalue())
50
+ json_loader = JSONLoader(temp_filepath)
51
+ json_doc = json_loader.load()
52
+ return json_doc
53
 
54
 
55
  # λ¬Έμ„œλ“€μ„ μ²˜λ¦¬ν•˜μ—¬ ν…μŠ€νŠΈ 청크둜 λ‚˜λˆ„λŠ” ν•¨μˆ˜μž…λ‹ˆλ‹€.