File size: 2,454 Bytes
7405474
 
 
 
 
 
 
 
2d94c1e
 
 
 
7405474
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
2d94c1e
 
 
 
 
 
7405474
 
 
 
 
 
 
 
 
 
 
 
 
 
 
2d94c1e
7405474
 
2d94c1e
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
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!")