Spaces:
Running
Running
import streamlit as st | |
import os | |
from PIL import Image | |
from chainguard.blockchain_logger import BlockchainLogger | |
# Initialize Blockchain Logger | |
blockchain_logger = BlockchainLogger() | |
# Define the directory for storing uploaded files | |
UPLOAD_DIR = "uploads" | |
os.makedirs(UPLOAD_DIR, exist_ok=True) | |
def log_metadata(file_name, tags, album): | |
"""Log photo metadata to Chagu blockchain.""" | |
metadata = { | |
"file_name": file_name, | |
"tags": tags, | |
"album": album | |
} | |
block_details = blockchain_logger.log_data(metadata) | |
return block_details | |
# Streamlit App Layout | |
st.title("Memora: Photo & Video Uploader") | |
st.subheader("Securely upload and organize your memories") | |
# File Upload | |
uploaded_files = st.file_uploader( | |
"Upload your photos or videos", accept_multiple_files=True, type=['jpg', 'jpeg', 'png', 'mp4', 'avi'] | |
) | |
if uploaded_files: | |
for uploaded_file in uploaded_files: | |
# Save uploaded file locally | |
file_path = os.path.join(UPLOAD_DIR, uploaded_file.name) | |
with open(file_path, "wb") as f: | |
f.write(uploaded_file.getbuffer()) | |
st.success(f"File {uploaded_file.name} saved locally in {UPLOAD_DIR}.") | |
# Display uploaded file | |
st.write(f"File Name: {uploaded_file.name}") | |
if uploaded_file.type.startswith('image'): | |
image = Image.open(uploaded_file) | |
st.image(image, caption=uploaded_file.name, use_column_width=True) | |
# Metadata Input | |
album = st.text_input(f"Album for {uploaded_file.name}", value="Default Album") | |
tags = st.text_input(f"Tags for {uploaded_file.name} (comma-separated)", value="") | |
# Log Metadata | |
if st.button(f"Log Metadata for {uploaded_file.name}"): | |
metadata = log_metadata(uploaded_file.name, tags.split(','), album) | |
st.write(f"Metadata logged successfully! Block Details: {metadata}") | |
# Blockchain Integrity Validation | |
if st.button("Validate Blockchain Integrity"): | |
is_valid = blockchain_logger.is_blockchain_valid() | |
if is_valid: | |
st.success("Blockchain Integrity: Valid β ") | |
else: | |
st.error("Blockchain Integrity: Invalid β") | |
if st.button("Simulate Blockchain Corruption"): | |
# Simulate corruption for testing | |
blockchain_logger.blockchain[1]['data'] = {"corrupted": "This block has been tampered with."} | |
st.warning("Blockchain corrupted for testing purposes!") | |