SeoJunn commited on
Commit
7ee82b4
Β·
1 Parent(s): 775c078

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +8 -6
app.py CHANGED
@@ -51,13 +51,15 @@ def get_csv_file(csv_docs):
51
  return csv_doc # μΆ”μΆœν•œ ν…μŠ€νŠΈλ₯Ό λ°˜ν™˜ν•©λ‹ˆλ‹€.
52
 
53
  def get_json_file(json_docs):
54
- temp_dir = tempfile.TemporaryDirectory() # μž„μ‹œ 디렉토리λ₯Ό μƒμ„±ν•©λ‹ˆλ‹€.
55
- temp_filepath = os.path.join(temp_dir.name, json_docs.name) # μž„μ‹œ 파일 경둜λ₯Ό μƒμ„±ν•©λ‹ˆλ‹€.
56
- with open(temp_filepath, "r") as f: # μž„μ‹œ νŒŒμΌμ„ λ°”μ΄λ„ˆλ¦¬ μ“°κΈ° λͺ¨λ“œλ‘œ μ—½λ‹ˆλ‹€.
57
- json_python = json.load(f) # PDF λ¬Έμ„œμ˜ λ‚΄μš©μ„ μž„μ‹œ νŒŒμΌμ— μ”λ‹ˆλ‹€.
58
- loader = JSONLoader(json_python, jq_schema='.messages[].content', text_content=False)
59
- data = loader.load()
 
60
  pprint('data json = ', data)
 
61
  pass
62
 
63
  # λ¬Έμ„œλ“€μ„ μ²˜λ¦¬ν•˜μ—¬ ν…μŠ€νŠΈ 청크둜 λ‚˜λˆ„λŠ” ν•¨μˆ˜μž…λ‹ˆλ‹€.
 
51
  return csv_doc # μΆ”μΆœν•œ ν…μŠ€νŠΈλ₯Ό λ°˜ν™˜ν•©λ‹ˆλ‹€.
52
 
53
  def get_json_file(json_docs):
54
+ temp_dir = tempfile.TemporaryDirectory() # Create a temporary directory.
55
+ temp_filepath = os.path.join(temp_dir.name, json_docs.name) # Create a temporary file path.
56
+
57
+ with open(temp_filepath, "wb") as f:
58
+ f.write(json_docs.read()) # Write the content of the uploaded JSON file to the temporary file.
59
+
60
+ data = json.loads(Path(temp_filepath).read_text()) # Load JSON data from the temporary file.
61
  pprint('data json = ', data)
62
+ return data
63
  pass
64
 
65
  # λ¬Έμ„œλ“€μ„ μ²˜λ¦¬ν•˜μ—¬ ν…μŠ€νŠΈ 청크둜 λ‚˜λˆ„λŠ” ν•¨μˆ˜μž…λ‹ˆλ‹€.