NLong commited on
Commit
79dddf4
Β·
verified Β·
1 Parent(s): 072518b

Upload app.py

Browse files
Files changed (1) hide show
  1. app.py +10 -22
app.py CHANGED
@@ -36,7 +36,7 @@ ENABLE_ENHANCED_RAG = True # Enable enhanced RAG system for Google Drive
36
  RAG_CONFIDENCE_THRESHOLD = 0.95 # 95% threshold for saving to RAG
37
 
38
  # Cloud Storage Configuration
39
- USE_CLOUD_STORAGE = True # Set to True to use cloud storage instead of local DB
40
  CLOUD_STORAGE_TYPE = "google_drive" # Options: "google_drive", "google_cloud", "local"
41
  GOOGLE_DRIVE_FILE_ID = None # Will be set when file is created
42
 
@@ -555,11 +555,16 @@ def populate_knowledge_base_from_training_data():
555
 
556
  return True
557
 
 
 
 
 
558
  except Exception as e:
559
- print(f"❌ Error populating knowledge base: {e}")
 
560
  return False
561
 
562
- # Populate knowledge base with training data on startup
563
  print("πŸš€ Populating knowledge base with training data...")
564
  populate_knowledge_base_from_training_data()
565
 
@@ -1553,25 +1558,8 @@ def analyze_news(news_text):
1553
  if gemini_analysis:
1554
  print(f" Analysis preview: {gemini_analysis[:300]}...")
1555
 
1556
- if gemini_max_confidence and gemini_max_confidence >= CONFIDENCE_THRESHOLD:
1557
- print(f"πŸš€ High Gemini confidence detected ({gemini_max_confidence:.1%}) - adding to knowledge base for RAG...")
1558
- final_prediction = "REAL" if gemini_real_percent > gemini_fake_percent else "FAKE"
1559
-
1560
- # Add to knowledge base
1561
- success = add_to_knowledge_base(
1562
- news_text=news_text,
1563
- prediction=final_prediction,
1564
- confidence=gemini_max_confidence, # Use Gemini confidence for RAG storage
1565
- search_results=search_results,
1566
- gemini_analysis=gemini_analysis
1567
- )
1568
-
1569
- if success:
1570
- print("βœ… Successfully added to knowledge base for future RAG retrieval!")
1571
- else:
1572
- print("⚠️ Failed to add to knowledge base (duplicate or error)")
1573
-
1574
- # Step 8: Enhanced RAG System - Save to Google Drive if confidence is high enough
1575
  print(f"\nπŸ” RAG SAVE DEBUG:")
1576
  print(f" ENABLE_ENHANCED_RAG: {ENABLE_ENHANCED_RAG}")
1577
  print(f" gemini_max_confidence: {gemini_max_confidence} ({gemini_max_confidence:.1%} if > 0)")
 
36
  RAG_CONFIDENCE_THRESHOLD = 0.95 # 95% threshold for saving to RAG
37
 
38
  # Cloud Storage Configuration
39
+ USE_CLOUD_STORAGE = False # Disabled - using Enhanced RAG system instead (no duplicates)
40
  CLOUD_STORAGE_TYPE = "google_drive" # Options: "google_drive", "google_cloud", "local"
41
  GOOGLE_DRIVE_FILE_ID = None # Will be set when file is created
42
 
 
555
 
556
  return True
557
 
558
+ except FileNotFoundError as e:
559
+ print(f"⚠️ Training data file not found: {e}")
560
+ print(" Knowledge base will start empty (this is OK)")
561
+ return False
562
  except Exception as e:
563
+ print(f"⚠️ Error populating knowledge base: {e}")
564
+ print(" Knowledge base will start empty (this is OK)")
565
  return False
566
 
567
+ # Populate knowledge base with training data on startup (optional)
568
  print("πŸš€ Populating knowledge base with training data...")
569
  populate_knowledge_base_from_training_data()
570
 
 
1558
  if gemini_analysis:
1559
  print(f" Analysis preview: {gemini_analysis[:300]}...")
1560
 
1561
+ # Step 7: Enhanced RAG System - Save to Google Drive if confidence is high enough
1562
+ # (Old knowledge base system disabled to avoid duplicates - Enhanced RAG is better)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1563
  print(f"\nπŸ” RAG SAVE DEBUG:")
1564
  print(f" ENABLE_ENHANCED_RAG: {ENABLE_ENHANCED_RAG}")
1565
  print(f" gemini_max_confidence: {gemini_max_confidence} ({gemini_max_confidence:.1%} if > 0)")