Nahyunho commited on
Commit
63e3a8a
β€’
1 Parent(s): a5ddf3b

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +21 -13
app.py CHANGED
@@ -28,26 +28,34 @@ def get_pdf_text(pdf_docs):
28
  # 과제
29
  # μ•„λž˜ ν…μŠ€νŠΈ μΆ”μΆœ ν•¨μˆ˜λ₯Ό μž‘μ„±
30
 
31
- def get_text_file(docs):
32
- with NamedTemporaryFile() as temp_file:
33
- temp_file.write(docs.getvalue())
34
- temp_file.seek(0)
 
35
  text_loader = TextLoader(temp_file.name)
36
  text_doc = text_loader.load()
37
 
38
  return text_doc
39
 
40
- def get_csv_file(docs):
41
- with NamedTemporaryFile() as temp_file:
42
- temp_file.write(docs.getvalue())
43
- temp_file.seek(0)
44
- text_loader = CSVLoader(temp_file.name)
45
- text_doc = text_loader.load()
 
46
 
47
- return text_doc
48
 
49
- def get_json_file(docs):
50
- pass
 
 
 
 
 
 
51
 
52
 
53
  # λ¬Έμ„œλ“€μ„ μ²˜λ¦¬ν•˜μ—¬ ν…μŠ€νŠΈ 청크둜 λ‚˜λˆ„λŠ” ν•¨μˆ˜μž…λ‹ˆλ‹€.
 
28
  # 과제
29
  # μ•„λž˜ ν…μŠ€νŠΈ μΆ”μΆœ ν•¨μˆ˜λ₯Ό μž‘μ„±
30
 
31
+ def get_text_file(text_docs):
32
+ temp_dir = tempfile.TemporaryDirectory() # μž„μ‹œ 디렉토리λ₯Ό μƒμ„±ν•©λ‹ˆλ‹€.
33
+ temp_filepath = os.path.join(temp_dir.name, text_docs.name) # μž„μ‹œ 파일 경둜λ₯Ό μƒμ„±ν•©λ‹ˆλ‹€.
34
+ with open(temp_filepath, "wb") as f: # μž„μ‹œ νŒŒμΌμ„ λ°”μ΄λ„ˆλ¦¬ μ“°κΈ° λͺ¨λ“œλ‘œ μ—½λ‹ˆλ‹€.
35
+ f.write(text_docs.getvalue())
36
  text_loader = TextLoader(temp_file.name)
37
  text_doc = text_loader.load()
38
 
39
  return text_doc
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(temp_file.name)
47
+ csv_doc = csv_loader.load()
48
 
49
+ return csv_doc
50
 
51
+ def get_json_file(json_docs):
52
+ temp_dir = tempfile.TemporaryDirectory() # μž„μ‹œ 디렉토리λ₯Ό μƒμ„±ν•©λ‹ˆλ‹€.
53
+ temp_filepath = os.path.join(temp_dir.name, json_docs.name) # μž„μ‹œ 파일 경둜λ₯Ό μƒμ„±ν•©λ‹ˆλ‹€.
54
+ with open(temp_filepath, "wb") as f: # μž„μ‹œ νŒŒμΌμ„ λ°”μ΄λ„ˆλ¦¬ μ“°κΈ° λͺ¨λ“œλ‘œ μ—½λ‹ˆλ‹€.
55
+ f.write(json_docs.getvalue())
56
+ json_loader = JSONLoader(temp_file.name,jq_schema='.messages[].content',text_content=False)
57
+ json_doc=json_loader.load
58
+ return json_doc
59
 
60
 
61
  # λ¬Έμ„œλ“€μ„ μ²˜λ¦¬ν•˜μ—¬ ν…μŠ€νŠΈ 청크둜 λ‚˜λˆ„λŠ” ν•¨μˆ˜μž…λ‹ˆλ‹€.