talexm commited on
Commit
8ce7f13
β€’
1 Parent(s): a9d98c6
Files changed (1) hide show
  1. app.py +46 -66
app.py CHANGED
@@ -1,9 +1,9 @@
 
 
1
  import streamlit as st
2
  from googlesearch import search
3
  import pandas as pd
4
- from pathlib import Path
5
  import os
6
- from PIL import Image
7
  from rag_sec.document_search_system import DocumentSearchSystem
8
  from chainguard.blockchain_logger import BlockchainLogger
9
 
@@ -14,7 +14,6 @@ blockchain_logger = BlockchainLogger()
14
  @st.cache_resource
15
  def initialize_system():
16
  """Initialize the DocumentSearchSystem and load documents."""
17
- home_dir = Path(os.getenv("HOME", "/"))
18
  system = DocumentSearchSystem(
19
  neo4j_uri="neo4j+s://0ca71b10.databases.neo4j.io",
20
  neo4j_user="neo4j",
@@ -23,82 +22,63 @@ def initialize_system():
23
  system.retriever.load_documents()
24
  return system
25
 
26
- # Initialize and load system
27
- st.write("Initializing the Document Search System...")
28
  system = initialize_system()
29
- st.success("System initialized and documents loaded!")
30
-
31
- # Directory for storing uploaded files
32
- UPLOAD_DIR = "uploaded_files"
33
- os.makedirs(UPLOAD_DIR, exist_ok=True)
34
 
35
  # Streamlit Layout
36
- st.title("Memora: Secure File Upload and Search with Blockchain & Neo4j")
37
- st.subheader("Securely upload, organize, and query your files")
38
 
39
- # Google Search Section
40
- st.subheader("Find User Information via Google Search")
41
- search_query = st.text_input("Enter a name or topic to search on Google")
42
- if st.button("Google Search"):
43
- if search_query:
 
 
44
  try:
45
- results = list(search(search_query, num_results=5)) # Fetch top 5 results
46
  if results:
47
- st.success(f"Top {len(results)} results for '{search_query}':")
48
- result_data = {"URL": results}
49
- df = pd.DataFrame(result_data)
50
- st.dataframe(df)
51
  else:
52
- st.warning("No results found for the search query.")
53
  except Exception as e:
54
  st.error(f"An error occurred during the search: {str(e)}")
55
  else:
56
- st.warning("Please enter a search query.")
57
-
58
- # File Upload Section
59
- uploaded_files = st.file_uploader("Upload your files", accept_multiple_files=True, type=['jpg', 'jpeg', 'png', 'mp4', 'avi'])
60
-
61
- if uploaded_files:
62
- for uploaded_file in uploaded_files:
63
- # Save file locally
64
- file_path = os.path.join(UPLOAD_DIR, uploaded_file.name)
65
- with open(file_path, "wb") as f:
66
- f.write(uploaded_file.getbuffer())
67
- st.success(f"File saved locally: {file_path}")
68
-
69
- # Display uploaded file details
70
- if uploaded_file.type.startswith('image'):
71
- image = Image.open(uploaded_file)
72
- st.image(image, caption=uploaded_file.name, use_column_width=True)
73
-
74
- # Metadata Input
75
- album = st.text_input(f"Album for {uploaded_file.name}", "Default Album")
76
- tags = st.text_input(f"Tags for {uploaded_file.name} (comma-separated)", "")
77
-
78
- # Log Metadata and Transaction
79
- if st.button(f"Log Metadata for {uploaded_file.name}"):
80
- metadata = {"file_name": uploaded_file.name, "tags": tags.split(','), "album": album}
81
- blockchain_details = blockchain_logger.log_data(metadata)
82
- blockchain_hash = blockchain_details.get("block_hash", "N/A")
83
-
84
- # Use Neo4jHandler from DocumentSearchSystem to log the transaction
85
- system.neo4j_handler.log_relationships(uploaded_file.name, tags, blockchain_hash, [album])
86
- st.write(f"Metadata logged successfully! Blockchain Details: {blockchain_details}")
87
-
88
- # Blockchain Integrity Validation
89
- if st.button("Validate Blockchain Integrity"):
90
- is_valid = blockchain_logger.is_blockchain_valid()
91
- st.write("Blockchain Integrity:", "Valid βœ…" if is_valid else "Invalid ❌")
92
-
93
- # Document Search Section
94
- st.subheader("Search Documents")
95
-
96
- # Query Input
97
  query = st.text_input("Enter your query (e.g., 'sports news', 'machine learning')")
98
 
99
- if st.button("Search"):
100
  if query:
101
- # Process query through the DocumentSearchSystem
102
  result = system.process_query(query)
103
  if result["status"] == "success":
104
  st.success(f"Query processed successfully!")
 
1
+ from pathlib import Path
2
+
3
  import streamlit as st
4
  from googlesearch import search
5
  import pandas as pd
 
6
  import os
 
7
  from rag_sec.document_search_system import DocumentSearchSystem
8
  from chainguard.blockchain_logger import BlockchainLogger
9
 
 
14
  @st.cache_resource
15
  def initialize_system():
16
  """Initialize the DocumentSearchSystem and load documents."""
 
17
  system = DocumentSearchSystem(
18
  neo4j_uri="neo4j+s://0ca71b10.databases.neo4j.io",
19
  neo4j_user="neo4j",
 
22
  system.retriever.load_documents()
23
  return system
24
 
25
+ # Initialize the system
 
26
  system = initialize_system()
 
 
 
 
 
27
 
28
  # Streamlit Layout
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")
34
+ user_name = st.text_input("Enter your name or handle to search for recent news", value="Talex Maxim")
35
+
36
+ if st.button("Search News About Me"):
37
+ if user_name:
38
+ st.write(f"Searching Google for news about **{user_name}**...")
39
  try:
40
+ results = list(search(user_name, num_results=5))
41
  if results:
42
+ st.success(f"Top {len(results)} results for '{user_name}':")
43
+ user_news_data = {"URL": results}
44
+ df_user_news = pd.DataFrame(user_news_data)
45
+ st.dataframe(df_user_news)
46
  else:
47
+ st.warning("No recent news found about you.")
48
  except Exception as e:
49
  st.error(f"An error occurred during the search: {str(e)}")
50
  else:
51
+ st.warning("Please enter your name or handle to search.")
52
+
53
+ # Google Search: Global News Categories
54
+ st.subheader("2. Global News Insights")
55
+ categories = ["Technology", "Sports", "Politics", "Entertainment", "Science"]
56
+ news_results = {}
57
+
58
+ if st.button("Fetch Global News"):
59
+ try:
60
+ for category in categories:
61
+ st.write(f"Fetching news for **{category}**...")
62
+ try:
63
+ category_results = list(search(f"latest {category} news", num_results=3))
64
+ news_results[category] = category_results
65
+ except Exception as e:
66
+ news_results[category] = [f"Error fetching news: {str(e)}"]
67
+
68
+ # Display results
69
+ for category, articles in news_results.items():
70
+ st.write(f"### Top News in {category}:")
71
+ for idx, article in enumerate(articles, start=1):
72
+ st.write(f"{idx}. [Read here]({article})")
73
+ except Exception as e:
74
+ st.error(f"An error occurred while fetching global news: {str(e)}")
75
+
76
+ # Document Search
77
+ st.subheader("3. Search Documents")
 
 
 
 
 
 
 
 
 
 
 
 
 
 
78
  query = st.text_input("Enter your query (e.g., 'sports news', 'machine learning')")
79
 
80
+ if st.button("Search Documents"):
81
  if query:
 
82
  result = system.process_query(query)
83
  if result["status"] == "success":
84
  st.success(f"Query processed successfully!")