Spaces:
Running
Running
File size: 3,909 Bytes
8ce7f13 7405474 a463e6e 3e269ec 7405474 5398274 7405474 3e269ec 759c15a 8ce7f13 759c15a 7405474 5398274 8ce7f13 7405474 8ce7f13 a463e6e 8ce7f13 a463e6e 8ce7f13 a463e6e 8ce7f13 a463e6e 8ce7f13 6dd2090 8ce7f13 6dd2090 759c15a 6dd2090 759c15a 0a4227c 6dd2090 759c15a |
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 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 |
from pathlib import Path
import streamlit as st
from googlesearch import search
import pandas as pd
import os
from rag_sec.document_search_system import DocumentSearchSystem
from chainguard.blockchain_logger import BlockchainLogger
# Blockchain Logger
blockchain_logger = BlockchainLogger()
# Initialize DocumentSearchSystem
@st.cache_resource
def initialize_system():
"""Initialize the DocumentSearchSystem and load documents."""
system = DocumentSearchSystem(
neo4j_uri="neo4j+s://0ca71b10.databases.neo4j.io",
neo4j_user="neo4j",
neo4j_password="HwGDOxyGS1-79nLeTiX5bx5ohoFSpvHCmTv8IRgt-lY"
)
system.retriever.load_documents()
return system
# Initialize the system
system = initialize_system()
# Streamlit Layout
st.title("Memora: Advanced Search and News Insights")
st.subheader("Personalized news and global updates at your fingertips")
# Google Search: User-Specific News
st.subheader("1. Latest News About You")
user_name = st.text_input("Enter your name or handle to search for recent news", value="Talex Maxim")
if st.button("Search News About Me"):
if user_name:
st.write(f"Searching Google for news about **{user_name}**...")
try:
results = list(search(user_name, num_results=5))
if results:
st.success(f"Top {len(results)} results for '{user_name}':")
user_news_data = {"URL": results}
df_user_news = pd.DataFrame(user_news_data)
st.dataframe(df_user_news)
else:
st.warning("No recent news found about you.")
except Exception as e:
st.error(f"An error occurred during the search: {str(e)}")
else:
st.warning("Please enter your name or handle to search.")
# Google Search: Global News Categories
st.subheader("2. Global News Insights")
categories = ["Technology", "Sports", "Politics", "Entertainment", "Science"]
news_results = {}
if st.button("Fetch Global News"):
try:
for category in categories:
st.write(f"Fetching news for **{category}**...")
try:
category_results = list(search(f"latest {category} news", num_results=3))
news_results[category] = category_results
except Exception as e:
news_results[category] = [f"Error fetching news: {str(e)}"]
# Display results
for category, articles in news_results.items():
st.write(f"### Top News in {category}:")
for idx, article in enumerate(articles, start=1):
st.write(f"{idx}. [Read here]({article})")
except Exception as e:
st.error(f"An error occurred while fetching global news: {str(e)}")
# Document Search
st.subheader("3. Search Documents")
query = st.text_input("Enter your query (e.g., 'sports news', 'machine learning')")
if st.button("Search Documents"):
if query:
result = system.process_query(query)
if result["status"] == "success":
st.success(f"Query processed successfully!")
st.write("### Query Response:")
st.write(result["response"])
st.write("### Retrieved Documents:")
for idx, doc in enumerate(result["retrieved_documents"], start=1):
st.write(f"**Document {idx}:**")
st.write(doc[:500]) # Display the first 500 characters
st.write("### Blockchain Details:")
st.json(result["blockchain_details"])
elif result["status"] == "no_results":
st.warning("No relevant documents found for your query.")
elif result["status"] == "rejected":
st.error(result["message"])
else:
st.warning("Please enter a query to search.")
# Debugging Section
if st.checkbox("Show Debug Information"):
st.write(f"Total documents loaded: {len(system.retriever.documents)}")
|