Spaces:
Sleeping
Sleeping
talexm
commited on
Commit
β’
7405474
1
Parent(s):
e893d68
building app category 4
Browse files
app.py
ADDED
@@ -0,0 +1,50 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import streamlit as st
|
2 |
+
import os
|
3 |
+
from PIL import Image
|
4 |
+
from chainguard.blockchain_logger import BlockchainLogger
|
5 |
+
|
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."""
|
12 |
+
metadata = {
|
13 |
+
"file_name": file_name,
|
14 |
+
"tags": tags,
|
15 |
+
"album": album
|
16 |
+
}
|
17 |
+
block_details = blockchain_logger.log_data(metadata)
|
18 |
+
return block_details
|
19 |
+
|
20 |
+
|
21 |
+
# Streamlit App Layout
|
22 |
+
st.title("Memora: Photo & Video Uploader")
|
23 |
+
st.subheader("Securely upload and organize your memories")
|
24 |
+
|
25 |
+
# File Upload
|
26 |
+
uploaded_files = st.file_uploader(
|
27 |
+
"Upload your photos or videos", accept_multiple_files=True, type=['jpg', 'jpeg', 'png', 'mp4', 'avi']
|
28 |
+
)
|
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'):
|
35 |
+
image = Image.open(uploaded_file)
|
36 |
+
st.image(image, caption=uploaded_file.name, use_column_width=True)
|
37 |
+
|
38 |
+
# Metadata Input
|
39 |
+
album = st.text_input(f"Album for {uploaded_file.name}", value="Default Album")
|
40 |
+
tags = st.text_input(f"Tags for {uploaded_file.name} (comma-separated)", value="")
|
41 |
+
|
42 |
+
# Log Metadata
|
43 |
+
if st.button(f"Log Metadata for {uploaded_file.name}"):
|
44 |
+
metadata = log_metadata(uploaded_file.name, tags.split(','), album)
|
45 |
+
st.write(f"Metadata logged successfully! Block Details: {metadata}")
|
46 |
+
|
47 |
+
# Display Blockchain Validation
|
48 |
+
if st.button("Validate Blockchain Integrity"):
|
49 |
+
is_valid = blockchain_logger.is_blockchain_valid()
|
50 |
+
st.write("Blockchain Integrity:", "Valid β
" if is_valid else "Invalid β")
|