Spaces:
Running
Running
talexm
commited on
Commit
·
b94e464
1
Parent(s):
b4b7246
update
Browse files
app.py
CHANGED
@@ -6,10 +6,15 @@ import pandas as pd
|
|
6 |
import os
|
7 |
from rag_sec.document_search_system import DocumentSearchSystem
|
8 |
from chainguard.blockchain_logger import BlockchainLogger
|
|
|
9 |
|
10 |
# Blockchain Logger
|
11 |
blockchain_logger = BlockchainLogger()
|
12 |
|
|
|
|
|
|
|
|
|
13 |
# Initialize DocumentSearchSystem
|
14 |
@st.cache_resource
|
15 |
def initialize_system():
|
@@ -25,9 +30,45 @@ def initialize_system():
|
|
25 |
# Initialize the system
|
26 |
system = initialize_system()
|
27 |
|
28 |
-
|
29 |
-
st.title("Memora: Advanced Search and News Insights")
|
30 |
st.subheader("Personalized news and global updates at your fingertips")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
31 |
|
32 |
# Google Search: User-Specific News
|
33 |
st.subheader("1. Latest News About You")
|
|
|
6 |
import os
|
7 |
from rag_sec.document_search_system import DocumentSearchSystem
|
8 |
from chainguard.blockchain_logger import BlockchainLogger
|
9 |
+
from PIL import Image
|
10 |
|
11 |
# Blockchain Logger
|
12 |
blockchain_logger = BlockchainLogger()
|
13 |
|
14 |
+
# Directory for storing uploaded files
|
15 |
+
UPLOAD_DIR = "uploaded_files"
|
16 |
+
os.makedirs(UPLOAD_DIR, exist_ok=True)
|
17 |
+
|
18 |
# Initialize DocumentSearchSystem
|
19 |
@st.cache_resource
|
20 |
def initialize_system():
|
|
|
30 |
# Initialize the system
|
31 |
system = initialize_system()
|
32 |
|
33 |
+
st.title("Memora: Secure File Upload and Search with Blockchain & Neo4j")
|
|
|
34 |
st.subheader("Personalized news and global updates at your fingertips")
|
35 |
+
# File Upload Section
|
36 |
+
uploaded_files = st.file_uploader("Upload your files", accept_multiple_files=True, type=['jpg', 'jpeg', 'png', 'mp4', 'avi'])
|
37 |
+
|
38 |
+
if uploaded_files:
|
39 |
+
for uploaded_file in uploaded_files:
|
40 |
+
# Save file locally
|
41 |
+
file_path = os.path.join(UPLOAD_DIR, uploaded_file.name)
|
42 |
+
with open(file_path, "wb") as f:
|
43 |
+
f.write(uploaded_file.getbuffer())
|
44 |
+
st.success(f"File saved locally: {file_path}")
|
45 |
+
|
46 |
+
# Display uploaded file details
|
47 |
+
if uploaded_file.type.startswith('image'):
|
48 |
+
image = Image.open(uploaded_file)
|
49 |
+
st.image(image, caption=uploaded_file.name, use_column_width=True)
|
50 |
+
|
51 |
+
# Metadata Input
|
52 |
+
album = st.text_input(f"Album for {uploaded_file.name}", "Default Album")
|
53 |
+
tags = st.text_input(f"Tags for {uploaded_file.name} (comma-separated)", "")
|
54 |
+
|
55 |
+
# Log Metadata and Transaction
|
56 |
+
if st.button(f"Log Metadata for {uploaded_file.name}"):
|
57 |
+
metadata = {"file_name": uploaded_file.name, "tags": tags.split(','), "album": album}
|
58 |
+
blockchain_details = blockchain_logger.log_data(metadata)
|
59 |
+
blockchain_hash = blockchain_details.get("block_hash", "N/A")
|
60 |
+
|
61 |
+
# Use Neo4jHandler from DocumentSearchSystem to log the transaction
|
62 |
+
system.neo4j_handler.log_relationships(uploaded_file.name, tags, blockchain_hash, [album])
|
63 |
+
st.write(f"Metadata logged successfully! Blockchain Details: {blockchain_details}")
|
64 |
+
|
65 |
+
# Blockchain Integrity Validation
|
66 |
+
if st.button("Validate Blockchain Integrity"):
|
67 |
+
is_valid = blockchain_logger.is_blockchain_valid()
|
68 |
+
st.write("Blockchain Integrity:", "Valid ✅" if is_valid else "Invalid ❌")
|
69 |
+
|
70 |
+
# Document Search Section
|
71 |
+
st.subheader("Search Documents")
|
72 |
|
73 |
# Google Search: User-Specific News
|
74 |
st.subheader("1. Latest News About You")
|