namkwonwoo commited on
Commit
75eb0a9
β€’
1 Parent(s): 5b9f44d

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +10 -11
app.py CHANGED
@@ -44,17 +44,16 @@ def get_csv_file(csv_docs):
44
  return csv_doc
45
 
46
  import json
47
- def get_json_file(docs):
48
- # Assuming docs is a file-like object from st.file_uploader
49
- json_docs = json.load(docs)
50
-
51
- # Extracting text from the JSON structure (modify this part based on your JSON structure)
52
- text_list = []
53
- for item in json_docs:
54
- if 'text' in item:
55
- text_list.append(item['text'])
56
-
57
- return text_list
58
 
59
 
60
  # λ¬Έμ„œλ“€μ„ μ²˜λ¦¬ν•˜μ—¬ ν…μŠ€νŠΈ 청크둜 λ‚˜λˆ„λŠ” ν•¨μˆ˜μž…λ‹ˆλ‹€.
 
44
  return csv_doc
45
 
46
  import json
47
+ def get_json_file(json_docs):
48
+ temp_dir = tempfile.TemporaryDirectory()
49
+ temp_filepath = os.path.join(temp_dir.name, json_docs.name)
50
+ with open(temp_filepath, "wb") as f:
51
+ f.write(json_docs.getvalue())
52
+ json_loader = JSONLoader(file_path = temp_filepath,
53
+ jq_schema = None,
54
+ text_content=False)
55
+ json_doc = json_loader.load()
56
+ return json_doc
 
57
 
58
 
59
  # λ¬Έμ„œλ“€μ„ μ²˜λ¦¬ν•˜μ—¬ ν…μŠ€νŠΈ 청크둜 λ‚˜λˆ„λŠ” ν•¨μˆ˜μž…λ‹ˆλ‹€.