Update app.py
Browse files
app.py
CHANGED
@@ -44,14 +44,26 @@ 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 |
-
|
54 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
55 |
except Exception as e:
|
56 |
st.error(f"Error loading JSON file: {e}")
|
57 |
return []
|
@@ -59,6 +71,7 @@ def get_json_file(json_docs):
|
|
59 |
|
60 |
|
61 |
|
|
|
62 |
# λ¬Έμλ€μ μ²λ¦¬νμ¬ ν
μ€νΈ μ²ν¬λ‘ λλλ ν¨μμ
λλ€.
|
63 |
def get_text_chunks(documents):
|
64 |
text_splitter = RecursiveCharacterTextSplitter(
|
|
|
44 |
return csv_doc # μΆμΆν ν
μ€νΈλ₯Ό λ°νν©λλ€.
|
45 |
|
46 |
def get_json_file(json_docs):
|
47 |
+
def get_json_file(json_docs):
|
48 |
try:
|
49 |
temp_dir = tempfile.TemporaryDirectory() # μμ λλ ν 리λ₯Ό μμ±ν©λλ€.
|
50 |
temp_filepath = os.path.join(temp_dir.name, "temp_file.json") # μμ νμΌ κ²½λ‘λ₯Ό μμ±ν©λλ€.
|
51 |
with open(temp_filepath, "wb") as f:
|
52 |
f.write(json_docs.getvalue()) # JSON λ¬Έμμ λ΄μ©μ μμ νμΌμ μλλ€.
|
53 |
+
|
54 |
+
# Load JSON file
|
55 |
+
json_loader = JSONLoader(temp_filepath, jq_schema='.messages[].content', text_content=False)
|
56 |
+
json_doc = json_loader.load()
|
57 |
+
|
58 |
+
# Remove empty chunks
|
59 |
+
non_empty_chunks = [chunk for chunk in json_doc if len(chunk) > 0]
|
60 |
+
|
61 |
+
# Check if any non-empty chunks are present
|
62 |
+
if not non_empty_chunks:
|
63 |
+
st.error("No non-empty chunks found in the JSON file.")
|
64 |
+
return []
|
65 |
+
|
66 |
+
return non_empty_chunks
|
67 |
except Exception as e:
|
68 |
st.error(f"Error loading JSON file: {e}")
|
69 |
return []
|
|
|
71 |
|
72 |
|
73 |
|
74 |
+
|
75 |
# λ¬Έμλ€μ μ²λ¦¬νμ¬ ν
μ€νΈ μ²ν¬λ‘ λλλ ν¨μμ
λλ€.
|
76 |
def get_text_chunks(documents):
|
77 |
text_splitter = RecursiveCharacterTextSplitter(
|