panda47 commited on
Commit
ed17b64
β€’
1 Parent(s): aa04651

Upload app.py

Browse files
Files changed (1) hide show
  1. app.py +27 -9
app.py CHANGED
@@ -28,17 +28,35 @@ def get_pdf_text(pdf_docs):
28
  # 과제
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
  # λ¬Έμ„œλ“€μ„ μ²˜λ¦¬ν•˜μ—¬ ν…μŠ€νŠΈ 청크둜 λ‚˜λˆ„λŠ” ν•¨μˆ˜μž…λ‹ˆλ‹€.
43
  def get_text_chunks(documents):
44
  text_splitter = RecursiveCharacterTextSplitter(
 
28
  # 과제
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())
36
+ txt_loader = TextLoader(temp_filepath)
37
+ txt_doc = txt_loader.load()
38
+ return txt_doc
39
+
40
+ def get_csv_file(csv_docs):
41
+ temp_dir = tempfile.TemporaryDirectory()
42
+ temp_filepath = os.path.join(temp_dir.name, csv_docs.name)
43
+ with open(temp_filepath, "wb") as f:
44
+ f.write(csv_docs.getvalue())
45
+ csv_loader = CSVLoader(temp_filepath)
46
+ csv_doc = csv_loader.load()
47
+ return csv_doc
48
+
49
+
50
+ def get_json_file(json_docs):
51
+ temp_dir = tempfile.TemporaryDirectory()
52
+ temp_filepath = os.path.join(temp_dir.name, json_docs.name)
53
+ with open(temp_filepath, "wb") as f:
54
+ f.write(json_docs.getvalue())
55
+ json_loader = JSONLoader(temp_filepath)
56
+ json_doc = json_loader.load()
57
+ return json_doc
58
 
59
 
 
 
 
 
 
 
 
60
  # λ¬Έμ„œλ“€μ„ μ²˜λ¦¬ν•˜μ—¬ ν…μŠ€νŠΈ 청크둜 λ‚˜λˆ„λŠ” ν•¨μˆ˜μž…λ‹ˆλ‹€.
61
  def get_text_chunks(documents):
62
  text_splitter = RecursiveCharacterTextSplitter(