han-byeol commited on
Commit
266b145
Β·
1 Parent(s): 1536a30

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +18 -6
app.py CHANGED
@@ -29,20 +29,32 @@ def get_pdf_text(pdf_docs):
29
  # μ•„λž˜ ν…μŠ€νŠΈ μΆ”μΆœ ν•¨μˆ˜λ₯Ό μž‘μ„±
30
 
31
  def get_text_file(txt_docs):
 
 
 
 
32
  text_loader = TextLoader(txt_docs.getvalue())
33
- text_content = text_loader.load()
34
- return text_content
35
 
36
 
37
  def get_csv_file(csv_docs):
 
 
 
 
38
  csv_loader = CSVLoader(csv_docs.getvalue())
39
- csv_content = csv_loader.load()
40
- return csv_content
41
 
42
  def get_json_file(json_docs):
 
 
 
 
43
  json_loader = JSONLoader(json_docs.getvalue())
44
- json_content = json_loader.load()
45
- return json_content
46
 
47
 
48
  # λ¬Έμ„œλ“€μ„ μ²˜λ¦¬ν•˜μ—¬ ν…μŠ€νŠΈ 청크둜 λ‚˜λˆ„λŠ” ν•¨μˆ˜μž…λ‹ˆλ‹€.
 
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
  text_loader = TextLoader(txt_docs.getvalue())
37
+ text_doc = text_loader.load()
38
+ return text_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())
46
  csv_loader = CSVLoader(csv_docs.getvalue())
47
+ csv_doc = csv_loader.load()
48
+ return csv_doc
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(json_docs.getvalue())
56
+ json_doc = json_loader.load()
57
+ return json_doc
58
 
59
 
60
  # λ¬Έμ„œλ“€μ„ μ²˜λ¦¬ν•˜μ—¬ ν…μŠ€νŠΈ 청크둜 λ‚˜λˆ„λŠ” ν•¨μˆ˜μž…λ‹ˆλ‹€.