Evan73 commited on
Commit
9a80e8e
1 Parent(s): 3c29b98

Add application file and requirements

Browse files
Files changed (2) hide show
  1. app.py +32 -0
  2. requirements.txt +1 -0
app.py ADDED
@@ -0,0 +1,32 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import streamlit as st
2
+ import json
3
+ import zipfile
4
+ import os
5
+
6
+ def process_json(json_file):
7
+ data = json.load(json_file)
8
+ # 在这里处理 JSON 数据
9
+ return f"Processed JSON file: {json_file.name}"
10
+
11
+ def process_zip(zip_file):
12
+ results = []
13
+ with zipfile.ZipFile(zip_file, 'r') as zip_ref:
14
+ zip_ref.extractall("temp")
15
+ for root, _, files in os.walk("temp"):
16
+ for filename in files:
17
+ if filename.endswith('.json'):
18
+ with open(os.path.join(root, filename)) as f:
19
+ data = json.load(f)
20
+ # 在这里处理解压后的 JSON 文件
21
+ results.append(f"Processed JSON file from ZIP: {filename}")
22
+ return results
23
+
24
+ st.title("JSON and ZIP File Processor")
25
+ uploaded_files = st.file_uploader("Upload JSON or ZIP files", type=["json", "zip"], accept_multiple_files=True)
26
+
27
+ if uploaded_files:
28
+ for file in uploaded_files:
29
+ if file.name.endswith(".json"):
30
+ st.write(process_json(file))
31
+ elif file.name.endswith(".zip"):
32
+ st.write(process_zip(file))
requirements.txt ADDED
@@ -0,0 +1 @@
 
 
1
+ streamlit