broadfield-dev commited on
Commit
e06bdde
·
verified ·
1 Parent(s): fea8c56

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +5 -4
app.py CHANGED
@@ -24,15 +24,16 @@ def load_feeds_in_background():
24
 
25
  @app.route('/')
26
  def index():
27
- # Show existing articles immediately
28
- stored_docs = vector_db.similarity_search("news", k=1000) # Show all available articles
 
29
  # Use a set to ensure unique articles by title, link, and description hash
30
  unique_articles = {}
31
  for doc in stored_docs:
32
  title = doc.metadata["title"]
33
  link = doc.metadata["link"]
34
  description = doc.metadata["original_description"]
35
- desc_hash = hashlib.md5(description.encode()).hexdigest()[:10]
36
  key = f"{title}|{link}|{desc_hash}"
37
  if key not in unique_articles:
38
  unique_articles[key] = {
@@ -61,7 +62,7 @@ def index():
61
  @app.route('/check_feeds', methods=['GET'])
62
  def check_feeds():
63
  try:
64
- # Check if vector DB has new documents (simplified check)
65
  docs = vector_db.similarity_search("news", k=1)
66
  if docs:
67
  logger.info("Feeds loaded successfully in vector DB")
 
24
 
25
  @app.route('/')
26
  def index():
27
+ # Show existing articles immediately, even if empty
28
+ stored_docs = vector_db.similarity_search("news", k=1000) # Try to retrieve all available articles
29
+ logger.info(f"Found {len(stored_docs)} documents in vector DB")
30
  # Use a set to ensure unique articles by title, link, and description hash
31
  unique_articles = {}
32
  for doc in stored_docs:
33
  title = doc.metadata["title"]
34
  link = doc.metadata["link"]
35
  description = doc.metadata["original_description"]
36
+ desc_hash = hashlib.md5(description.encode()).hexdigest()
37
  key = f"{title}|{link}|{desc_hash}"
38
  if key not in unique_articles:
39
  unique_articles[key] = {
 
62
  @app.route('/check_feeds', methods=['GET'])
63
  def check_feeds():
64
  try:
65
+ # Check if vector DB has new or updated documents
66
  docs = vector_db.similarity_search("news", k=1)
67
  if docs:
68
  logger.info("Feeds loaded successfully in vector DB")