Update app.py
Browse files
app.py
CHANGED
@@ -12,8 +12,14 @@ from modules.record import DatabaseComponent # Import DatabaseComponent
|
|
12 |
# Load environment variables
|
13 |
load_dotenv()
|
14 |
|
15 |
-
# Initialize database
|
16 |
-
db =
|
|
|
|
|
|
|
|
|
|
|
|
|
17 |
executor = ThreadPoolExecutor(max_workers=3)
|
18 |
|
19 |
# Constants for file paths and API keys
|
@@ -69,8 +75,9 @@ def evaluate_news(news_input):
|
|
69 |
else:
|
70 |
status = f"**{truth_percentage:.0f}% chances to be true** - This news is unlikely to be true. Proceed with caution."
|
71 |
|
72 |
-
# Save result in database
|
73 |
-
db
|
|
|
74 |
|
75 |
# Initial result
|
76 |
result = f"**News:** \"{news_text[:300]}...\"\n\n"
|
@@ -99,6 +106,9 @@ def evaluate_news(news_input):
|
|
99 |
|
100 |
# Function to fetch dashboard data
|
101 |
def fetch_dashboard_data():
|
|
|
|
|
|
|
102 |
total_news = db.get_total_news_count()
|
103 |
last_10_news = db.get_last_10_news()
|
104 |
|
@@ -152,4 +162,4 @@ with gr.Blocks(css="""
|
|
152 |
gr.Markdown("### **About EchoTruth**")
|
153 |
gr.Markdown("EchoTruth uses AI to help users verify news authenticity in real-time.")
|
154 |
|
155 |
-
demo.launch()
|
|
|
12 |
# Load environment variables
|
13 |
load_dotenv()
|
14 |
|
15 |
+
# Initialize database (handle connection failures)
|
16 |
+
db = None
|
17 |
+
try:
|
18 |
+
db = DatabaseComponent()
|
19 |
+
except Exception as e:
|
20 |
+
print(f"[ERROR] Database connection failed: {str(e)}")
|
21 |
+
|
22 |
+
# Initialize thread executor
|
23 |
executor = ThreadPoolExecutor(max_workers=3)
|
24 |
|
25 |
# Constants for file paths and API keys
|
|
|
75 |
else:
|
76 |
status = f"**{truth_percentage:.0f}% chances to be true** - This news is unlikely to be true. Proceed with caution."
|
77 |
|
78 |
+
# Save result in database if connection is available
|
79 |
+
if db is not None:
|
80 |
+
db.save_news_verification(news_text[:100], truth_score, first_citation)
|
81 |
|
82 |
# Initial result
|
83 |
result = f"**News:** \"{news_text[:300]}...\"\n\n"
|
|
|
106 |
|
107 |
# Function to fetch dashboard data
|
108 |
def fetch_dashboard_data():
|
109 |
+
if db is None:
|
110 |
+
return "**⚠️ Database unavailable. Recent verification records cannot be displayed.**"
|
111 |
+
|
112 |
total_news = db.get_total_news_count()
|
113 |
last_10_news = db.get_last_10_news()
|
114 |
|
|
|
162 |
gr.Markdown("### **About EchoTruth**")
|
163 |
gr.Markdown("EchoTruth uses AI to help users verify news authenticity in real-time.")
|
164 |
|
165 |
+
demo.launch()
|