Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -44,7 +44,7 @@ def flatten_json(data, flattened=None, prefix=''):
|
|
| 44 |
new_key = f"{prefix}[{i}]" if prefix else str(i)
|
| 45 |
flatten_json(item, flattened, new_key)
|
| 46 |
elif data is not None and data != "":
|
| 47 |
-
flattened[prefix] =
|
| 48 |
|
| 49 |
return flattened
|
| 50 |
|
|
@@ -64,16 +64,15 @@ uploaded_zips = st.file_uploader("Upload ZIP files containing JSON files:", type
|
|
| 64 |
|
| 65 |
if uploaded_zips:
|
| 66 |
# Process all uploaded ZIP files
|
| 67 |
-
all_flattened_json =
|
| 68 |
-
total_files_processed = 0
|
| 69 |
|
| 70 |
for zip_file in uploaded_zips:
|
| 71 |
flattened_json = extract_and_combine_zip(zip_file)
|
| 72 |
-
|
| 73 |
-
|
| 74 |
|
| 75 |
# Create a DataFrame from the flattened JSON data
|
| 76 |
-
df = pd.DataFrame(
|
| 77 |
|
| 78 |
# Convert all object columns to string to avoid Arrow conversion issues
|
| 79 |
for col in df.select_dtypes(include=['object']).columns:
|
|
@@ -84,8 +83,8 @@ if uploaded_zips:
|
|
| 84 |
json_bytes = flattened_json_str.encode()
|
| 85 |
|
| 86 |
# Display processing summary
|
| 87 |
-
st.write(f"Processed {
|
| 88 |
-
st.write(f"Total
|
| 89 |
|
| 90 |
# Create columns for download buttons
|
| 91 |
col1, col2 = st.columns(2)
|
|
@@ -110,4 +109,8 @@ if uploaded_zips:
|
|
| 110 |
)
|
| 111 |
|
| 112 |
# Add a success message
|
| 113 |
-
st.success(f"All ZIP files have been successfully processed.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 44 |
new_key = f"{prefix}[{i}]" if prefix else str(i)
|
| 45 |
flatten_json(item, flattened, new_key)
|
| 46 |
elif data is not None and data != "":
|
| 47 |
+
flattened[prefix] = value
|
| 48 |
|
| 49 |
return flattened
|
| 50 |
|
|
|
|
| 64 |
|
| 65 |
if uploaded_zips:
|
| 66 |
# Process all uploaded ZIP files
|
| 67 |
+
all_flattened_json = []
|
|
|
|
| 68 |
|
| 69 |
for zip_file in uploaded_zips:
|
| 70 |
flattened_json = extract_and_combine_zip(zip_file)
|
| 71 |
+
flattened_json['zip_file_name'] = zip_file.name # Add ZIP file name to the flattened JSON
|
| 72 |
+
all_flattened_json.append(flattened_json)
|
| 73 |
|
| 74 |
# Create a DataFrame from the flattened JSON data
|
| 75 |
+
df = pd.DataFrame(all_flattened_json)
|
| 76 |
|
| 77 |
# Convert all object columns to string to avoid Arrow conversion issues
|
| 78 |
for col in df.select_dtypes(include=['object']).columns:
|
|
|
|
| 83 |
json_bytes = flattened_json_str.encode()
|
| 84 |
|
| 85 |
# Display processing summary
|
| 86 |
+
st.write(f"Processed {len(uploaded_zips)} ZIP file(s)")
|
| 87 |
+
st.write(f"Total rows in the output: {len(all_flattened_json)}")
|
| 88 |
|
| 89 |
# Create columns for download buttons
|
| 90 |
col1, col2 = st.columns(2)
|
|
|
|
| 109 |
)
|
| 110 |
|
| 111 |
# Add a success message
|
| 112 |
+
st.success(f"All ZIP files have been successfully processed. Each ZIP file is represented as a separate row in the output. You can now download the flattened JSON file or the Excel file.")
|
| 113 |
+
|
| 114 |
+
# Display a preview of the DataFrame
|
| 115 |
+
st.write("Preview of the processed data:")
|
| 116 |
+
st.dataframe(df.head())
|