Update app.py
Browse files
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 |
-
|
48 |
-
|
49 |
-
|
50 |
-
|
51 |
-
|
52 |
-
|
53 |
-
|
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 |
|