biglohi124 commited on
Commit
4647bc2
Β·
1 Parent(s): 14e7cb3

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +19 -3
app.py CHANGED
@@ -38,11 +38,27 @@ def get_text_file(text_docs):
38
  return text_doc
39
 
40
 
41
- def get_csv_file(docs):
42
- pass
 
 
 
 
 
 
 
43
 
44
  def get_json_file(docs):
45
- pass
 
 
 
 
 
 
 
 
 
46
 
47
 
48
  # λ¬Έμ„œλ“€μ„ μ²˜λ¦¬ν•˜μ—¬ ν…μŠ€νŠΈ 청크둜 λ‚˜λˆ„λŠ” ν•¨μˆ˜μž…λ‹ˆλ‹€.
 
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()) # csv λ¬Έμ„œμ˜ λ‚΄μš©μ„ μž„μ‹œ νŒŒμΌμ— μ”λ‹ˆλ‹€.
46
+ csv_loader = CSVLoader(temp_filepath)
47
+ csv_doc = csv_loader.load()
48
+ return csv_doc
49
+
50
 
51
  def get_json_file(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()) # json λ¬Έμ„œμ˜ λ‚΄μš©μ„ μž„μ‹œ νŒŒμΌμ— μ”λ‹ˆλ‹€.
56
+ json_loader = JSONLoader(temp_filepath,
57
+ jq_schema='.messages[].content',
58
+ text_content=False)
59
+ json_doc = json_loader.load()
60
+ return json_doc
61
+
62
 
63
 
64
  # λ¬Έμ„œλ“€μ„ μ²˜λ¦¬ν•˜μ—¬ ν…μŠ€νŠΈ 청크둜 λ‚˜λˆ„λŠ” ν•¨μˆ˜μž…λ‹ˆλ‹€.