Spaces:
Running
Running
import streamlit as st | |
import json | |
import zipfile | |
import os | |
def process_json(json_file): | |
data = json.load(json_file) | |
# 在这里处理 JSON 数据 | |
return f"Processed JSON file: {json_file.name}" | |
def process_zip(zip_file): | |
results = [] | |
with zipfile.ZipFile(zip_file, 'r') as zip_ref: | |
zip_ref.extractall("temp") | |
for root, _, files in os.walk("temp"): | |
for filename in files: | |
if filename.endswith('.json'): | |
with open(os.path.join(root, filename)) as f: | |
data = json.load(f) | |
# 在这里处理解压后的 JSON 文件 | |
results.append(f"Processed JSON file from ZIP: {filename}") | |
return results | |
st.title("JSON and ZIP File Processor") | |
uploaded_files = st.file_uploader("Upload JSON or ZIP files", type=["json", "zip"], accept_multiple_files=True) | |
if uploaded_files: | |
for file in uploaded_files: | |
if file.name.endswith(".json"): | |
st.write(process_json(file)) | |
elif file.name.endswith(".zip"): | |
st.write(process_zip(file)) | |