namkwonwoo commited on
Commit
9abc8de
Β·
1 Parent(s): 768918b

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +22 -8
app.py CHANGED
@@ -43,14 +43,28 @@ def get_csv_file(csv_docs):
43
  csv_doc = csv_loader.load()
44
  return csv_doc
45
 
46
- def get_json_file(json_docs):
47
- temp_dir = tempfile.TemporaryDirectory()
48
- temp_filepath = os.path.join(temp_dir.name, json_docs.name)
49
- with open(temp_filepath, "wb") as f:
50
- f.write(json_docs.getvalue())
51
- json_loader = JSONLoader(temp_filepath)
52
- json_doc = json_loader.load()
53
- return json_doc
 
 
 
 
 
 
 
 
 
 
 
 
 
 
54
 
55
 
56
  # λ¬Έμ„œλ“€μ„ μ²˜λ¦¬ν•˜μ—¬ ν…μŠ€νŠΈ 청크둜 λ‚˜λˆ„λŠ” ν•¨μˆ˜μž…λ‹ˆλ‹€.
 
43
  csv_doc = csv_loader.load()
44
  return csv_doc
45
 
46
+ import json
47
+
48
+ def get_json_file(docs):
49
+ # 파일 μœ ν˜•μ΄ JSON인지 ν™•μΈν•©λ‹ˆλ‹€.
50
+ if docs.type == 'application/json':
51
+ # JSON 파일의 λ‚΄μš©μ„ μ½μŠ΅λ‹ˆλ‹€.
52
+ json_content = docs.getvalue().decode('utf-8')
53
+
54
+ # JSON λ‚΄μš©μ„ νŒŒμ‹±ν•©λ‹ˆλ‹€.
55
+ try:
56
+ json_data = json.loads(json_content)
57
+ except json.JSONDecodeError:
58
+ st.error("JSON 파일 λ””μ½”λ”© 쀑 였λ₯˜κ°€ λ°œμƒν–ˆμŠ΅λ‹ˆλ‹€.")
59
+ return []
60
+
61
+ # JSON λ°μ΄ν„°μ—μ„œ ν…μŠ€νŠΈλ₯Ό μΆ”μΆœν•©λ‹ˆλ‹€ (μ‹€μ œ JSON ꡬ쑰에 따라 μˆ˜μ • ν•„μš”).
62
+ text_list = []
63
+ for item in json_data:
64
+ if 'text' in item:
65
+ text_list.append(item['text'])
66
+
67
+ return text_list
68
 
69
 
70
  # λ¬Έμ„œλ“€μ„ μ²˜λ¦¬ν•˜μ—¬ ν…μŠ€νŠΈ 청크둜 λ‚˜λˆ„λŠ” ν•¨μˆ˜μž…λ‹ˆλ‹€.