Thback commited on
Commit
b029abd
ยท
1 Parent(s): cf9ac6f

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +7 -23
app.py CHANGED
@@ -44,29 +44,13 @@ def get_csv_file(csv_docs):
44
  return csv_doc # ์ถ”์ถœํ•œ ํ…์ŠคํŠธ๋ฅผ ๋ฐ˜ํ™˜ํ•ฉ๋‹ˆ๋‹ค.
45
 
46
  def get_json_file(json_docs):
47
- try:
48
- temp_dir = tempfile.TemporaryDirectory() # ์ž„์‹œ ๋””๋ ‰ํ† ๋ฆฌ๋ฅผ ์ƒ์„ฑํ•ฉ๋‹ˆ๋‹ค.
49
- temp_filepath = os.path.join(temp_dir.name, "temp_file.json") # ์ž„์‹œ ํŒŒ์ผ ๊ฒฝ๋กœ๋ฅผ ์ƒ์„ฑํ•ฉ๋‹ˆ๋‹ค.
50
- with open(temp_filepath, "wb") as f:
51
- f.write(json_docs.getvalue()) # JSON ๋ฌธ์„œ์˜ ๋‚ด์šฉ์„ ์ž„์‹œ ํŒŒ์ผ์— ์”๋‹ˆ๋‹ค.
52
-
53
- # Load JSON file
54
- json_loader = JSONLoader(temp_filepath, jq_schema='.messages[].content', text_content=False)
55
- json_doc = json_loader.load()
56
-
57
- # Remove empty chunks
58
- non_empty_chunks = [chunk for chunk in json_doc if len(chunk) > 0]
59
-
60
- # Check if any non-empty chunks are present
61
- if not non_empty_chunks:
62
- st.error("No non-empty chunks found in the JSON file.")
63
- return []
64
-
65
- return non_empty_chunks
66
- except Exception as e:
67
- st.error(f"Error loading JSON file: {e}")
68
- return []
69
-
70
 
71
 
72
 
 
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, "temp_file.json") # ์ž„์‹œ ํŒŒ์ผ ๊ฒฝ๋กœ๋ฅผ ์ƒ์„ฑํ•ฉ๋‹ˆ๋‹ค.
49
+ with open(temp_filepath, "wb") as f:
50
+ f.write(json_docs.getvalue()) # JSON ๋ฌธ์„œ์˜ ๋‚ด์šฉ์„ ์ž„์‹œ ํŒŒ์ผ์— ์”๋‹ˆ๋‹ค.
51
+ json_loader = JSONLoader(temp_filepath, jq_schema='.messages[].content', text_content=False) # JSONLoader๋ฅผ ์‚ฌ์šฉํ•ด JSON๋ฅผ ๋กœ๋“œํ•ฉ๋‹ˆ๋‹ค.
52
+ json_doc = json_loader.load() # ํ…์ŠคํŠธ๋ฅผ ์ถ”์ถœํ•ฉ๋‹ˆ๋‹ค.
53
+ return json_doc # ์ถ”์ถœํ•œ ํ…์ŠคํŠธ๋ฅผ ๋ฐ˜ํ™˜ํ•ฉ๋‹ˆ๋‹ค.
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
54
 
55
 
56