Spaces:
Running
Running
talexm
commited on
Commit
β’
2d94c1e
1
Parent(s):
7405474
update
Browse files
app.py
CHANGED
@@ -6,6 +6,10 @@ from chainguard.blockchain_logger import BlockchainLogger
|
|
6 |
# Initialize Blockchain Logger
|
7 |
blockchain_logger = BlockchainLogger()
|
8 |
|
|
|
|
|
|
|
|
|
9 |
|
10 |
def log_metadata(file_name, tags, album):
|
11 |
"""Log photo metadata to Chagu blockchain."""
|
@@ -29,6 +33,12 @@ uploaded_files = st.file_uploader(
|
|
29 |
|
30 |
if uploaded_files:
|
31 |
for uploaded_file in uploaded_files:
|
|
|
|
|
|
|
|
|
|
|
|
|
32 |
# Display uploaded file
|
33 |
st.write(f"File Name: {uploaded_file.name}")
|
34 |
if uploaded_file.type.startswith('image'):
|
@@ -44,7 +54,14 @@ if uploaded_files:
|
|
44 |
metadata = log_metadata(uploaded_file.name, tags.split(','), album)
|
45 |
st.write(f"Metadata logged successfully! Block Details: {metadata}")
|
46 |
|
47 |
-
#
|
48 |
if st.button("Validate Blockchain Integrity"):
|
49 |
is_valid = blockchain_logger.is_blockchain_valid()
|
50 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
6 |
# Initialize Blockchain Logger
|
7 |
blockchain_logger = BlockchainLogger()
|
8 |
|
9 |
+
# Define the directory for storing uploaded files
|
10 |
+
UPLOAD_DIR = "uploads"
|
11 |
+
os.makedirs(UPLOAD_DIR, exist_ok=True)
|
12 |
+
|
13 |
|
14 |
def log_metadata(file_name, tags, album):
|
15 |
"""Log photo metadata to Chagu blockchain."""
|
|
|
33 |
|
34 |
if uploaded_files:
|
35 |
for uploaded_file in uploaded_files:
|
36 |
+
# Save uploaded file locally
|
37 |
+
file_path = os.path.join(UPLOAD_DIR, uploaded_file.name)
|
38 |
+
with open(file_path, "wb") as f:
|
39 |
+
f.write(uploaded_file.getbuffer())
|
40 |
+
st.success(f"File {uploaded_file.name} saved locally in {UPLOAD_DIR}.")
|
41 |
+
|
42 |
# Display uploaded file
|
43 |
st.write(f"File Name: {uploaded_file.name}")
|
44 |
if uploaded_file.type.startswith('image'):
|
|
|
54 |
metadata = log_metadata(uploaded_file.name, tags.split(','), album)
|
55 |
st.write(f"Metadata logged successfully! Block Details: {metadata}")
|
56 |
|
57 |
+
# Blockchain Integrity Validation
|
58 |
if st.button("Validate Blockchain Integrity"):
|
59 |
is_valid = blockchain_logger.is_blockchain_valid()
|
60 |
+
if is_valid:
|
61 |
+
st.success("Blockchain Integrity: Valid β
")
|
62 |
+
else:
|
63 |
+
st.error("Blockchain Integrity: Invalid β")
|
64 |
+
if st.button("Simulate Blockchain Corruption"):
|
65 |
+
# Simulate corruption for testing
|
66 |
+
blockchain_logger.blockchain[1]['data'] = {"corrupted": "This block has been tampered with."}
|
67 |
+
st.warning("Blockchain corrupted for testing purposes!")
|