Spaces:
Running
Running
Update UI Frontend + API
Browse files- backend/server/api_server.py +3 -3
- components/sidebar.py +22 -1
backend/server/api_server.py
CHANGED
|
@@ -5,9 +5,9 @@ from dotenv import load_dotenv
|
|
| 5 |
from fastapi import FastAPI, HTTPException
|
| 6 |
from pydantic import BaseModel
|
| 7 |
from typing import List, Dict, Any, Optional
|
| 8 |
-
from src.database.db_manager import get_db_connection
|
| 9 |
-
from src.nl2sql.hf_engine import get_models, DEFAULT_MODEL_ID
|
| 10 |
-
from src.nl2sql.sql_agent import nl2sql_agent
|
| 11 |
|
| 12 |
load_dotenv()
|
| 13 |
app = FastAPI(title="NL2SQL Backend API")
|
|
|
|
| 5 |
from fastapi import FastAPI, HTTPException
|
| 6 |
from pydantic import BaseModel
|
| 7 |
from typing import List, Dict, Any, Optional
|
| 8 |
+
from backend.src.database.db_manager import get_db_connection
|
| 9 |
+
from backend.src.nl2sql.hf_engine import get_models, DEFAULT_MODEL_ID
|
| 10 |
+
from backend.src.nl2sql.sql_agent import nl2sql_agent
|
| 11 |
|
| 12 |
load_dotenv()
|
| 13 |
app = FastAPI(title="NL2SQL Backend API")
|
components/sidebar.py
CHANGED
|
@@ -5,6 +5,21 @@ from utils.api import get_available_models
|
|
| 5 |
from backend.src.database.db_manager import get_db_connection
|
| 6 |
from components.auth import render_auth_dialog, save_chat_history, save_userDB, load_userDB
|
| 7 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 8 |
@st.dialog("Delete Confirmation")
|
| 9 |
def confirm_delete(idx, session_title):
|
| 10 |
st.warning(f"Are you sure you want to delete '{session_title}'?")
|
|
@@ -58,7 +73,13 @@ def render_sidebar():
|
|
| 58 |
st.divider()
|
| 59 |
|
| 60 |
st.subheader("Database Connection")
|
| 61 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 62 |
|
| 63 |
st.subheader("Model Selector")
|
| 64 |
available_models = get_available_models()
|
|
|
|
| 5 |
from backend.src.database.db_manager import get_db_connection
|
| 6 |
from components.auth import render_auth_dialog, save_chat_history, save_userDB, load_userDB
|
| 7 |
|
| 8 |
+
@st.cache_data(ttl=60)
|
| 9 |
+
def check_db_connection():
|
| 10 |
+
"""
|
| 11 |
+
Ping the database to check connectivity status
|
| 12 |
+
Cached for 60 seconds to avoid DB overloading on Streamlit rerun
|
| 13 |
+
"""
|
| 14 |
+
try:
|
| 15 |
+
conn = get_db_connection()
|
| 16 |
+
# Close connection immediately after successful ping to free resources
|
| 17 |
+
if hasattr(conn, 'close'):
|
| 18 |
+
conn.close()
|
| 19 |
+
return True, None
|
| 20 |
+
except Exception as e:
|
| 21 |
+
return False, str(e)
|
| 22 |
+
|
| 23 |
@st.dialog("Delete Confirmation")
|
| 24 |
def confirm_delete(idx, session_title):
|
| 25 |
st.warning(f"Are you sure you want to delete '{session_title}'?")
|
|
|
|
| 73 |
st.divider()
|
| 74 |
|
| 75 |
st.subheader("Database Connection")
|
| 76 |
+
is_connected, error_msg = check_db_connection()
|
| 77 |
+
|
| 78 |
+
if is_connected:
|
| 79 |
+
st.success(icon=":material/database:", body="Connected")
|
| 80 |
+
else:
|
| 81 |
+
st.error(icon=":material/database_off:", body="Disconnected")
|
| 82 |
+
st.caption("Connection failed. Please check your configuration.")
|
| 83 |
|
| 84 |
st.subheader("Model Selector")
|
| 85 |
available_models = get_available_models()
|