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