Spaces:
Running
Running
talexm
commited on
Commit
β’
8ce7f13
1
Parent(s):
a9d98c6
news
Browse files
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
|
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:
|
37 |
-
st.subheader("
|
38 |
|
39 |
-
# Google Search
|
40 |
-
st.subheader("
|
41 |
-
|
42 |
-
|
43 |
-
|
|
|
|
|
44 |
try:
|
45 |
-
results = list(search(
|
46 |
if results:
|
47 |
-
st.success(f"Top {len(results)} results for '{
|
48 |
-
|
49 |
-
|
50 |
-
st.dataframe(
|
51 |
else:
|
52 |
-
st.warning("No
|
53 |
except Exception as e:
|
54 |
st.error(f"An error occurred during the search: {str(e)}")
|
55 |
else:
|
56 |
-
st.warning("Please enter
|
57 |
-
|
58 |
-
#
|
59 |
-
|
60 |
-
|
61 |
-
|
62 |
-
|
63 |
-
|
64 |
-
|
65 |
-
|
66 |
-
|
67 |
-
|
68 |
-
|
69 |
-
|
70 |
-
|
71 |
-
|
72 |
-
|
73 |
-
|
74 |
-
|
75 |
-
|
76 |
-
|
77 |
-
|
78 |
-
|
79 |
-
|
80 |
-
|
81 |
-
|
82 |
-
|
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!")
|