Spaces:
Build error
Build error
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,4 +1,7 @@
|
|
| 1 |
import streamlit as st
|
|
|
|
|
|
|
|
|
|
| 2 |
from components.chat import display_chat_interface
|
| 3 |
from utils.database import (
|
| 4 |
display_vector_store_info,
|
|
@@ -7,29 +10,55 @@ from utils.database import (
|
|
| 7 |
create_tables
|
| 8 |
)
|
| 9 |
import time
|
| 10 |
-
import os
|
| 11 |
|
| 12 |
def initialize_database():
|
| 13 |
-
"""Initialize database connection and tables."""
|
| 14 |
-
|
| 15 |
-
|
| 16 |
-
|
| 17 |
-
|
| 18 |
-
os.
|
| 19 |
-
|
| 20 |
-
|
| 21 |
-
|
| 22 |
-
|
| 23 |
-
|
| 24 |
-
|
| 25 |
-
|
| 26 |
-
|
| 27 |
-
#
|
| 28 |
-
|
| 29 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 30 |
else:
|
| 31 |
-
st.
|
| 32 |
-
return
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 33 |
|
| 34 |
def display_example_questions():
|
| 35 |
examples = [
|
|
|
|
| 1 |
import streamlit as st
|
| 2 |
+
import os
|
| 3 |
+
import sqlite3
|
| 4 |
+
from pathlib import Path
|
| 5 |
from components.chat import display_chat_interface
|
| 6 |
from utils.database import (
|
| 7 |
display_vector_store_info,
|
|
|
|
| 10 |
create_tables
|
| 11 |
)
|
| 12 |
import time
|
|
|
|
| 13 |
|
| 14 |
def initialize_database():
|
| 15 |
+
"""Initialize database connection and tables with debug info."""
|
| 16 |
+
try:
|
| 17 |
+
if 'db_conn' not in st.session_state:
|
| 18 |
+
# Create the data directory if it doesn't exist
|
| 19 |
+
data_dir = "data"
|
| 20 |
+
st.write(f"Checking data directory: {os.path.abspath(data_dir)}")
|
| 21 |
+
|
| 22 |
+
if not os.path.exists(data_dir):
|
| 23 |
+
st.write("Data directory not found, creating...")
|
| 24 |
+
os.makedirs(data_dir)
|
| 25 |
+
st.write("Data directory created successfully")
|
| 26 |
+
else:
|
| 27 |
+
st.write("Data directory already exists")
|
| 28 |
+
|
| 29 |
+
# Initialize database connection
|
| 30 |
+
db_path = os.path.join(data_dir, 'rfp_analysis.db')
|
| 31 |
+
st.write(f"Full database path: {os.path.abspath(db_path)}")
|
| 32 |
+
|
| 33 |
+
# Check write permissions
|
| 34 |
+
try:
|
| 35 |
+
with open(db_path, 'a') as f:
|
| 36 |
+
pass
|
| 37 |
+
st.write("Write permission test successful")
|
| 38 |
+
except IOError as e:
|
| 39 |
+
st.error(f"Write permission error: {str(e)}")
|
| 40 |
+
return False
|
| 41 |
+
|
| 42 |
+
conn = create_connection(db_path)
|
| 43 |
+
|
| 44 |
+
if conn is not None:
|
| 45 |
+
st.write("Creating database tables...")
|
| 46 |
+
create_tables(conn)
|
| 47 |
+
st.session_state.db_conn = conn
|
| 48 |
+
st.write("Database initialization complete!")
|
| 49 |
+
return True
|
| 50 |
+
else:
|
| 51 |
+
st.error("Failed to create database connection")
|
| 52 |
+
return False
|
| 53 |
else:
|
| 54 |
+
st.write("Database connection already exists in session state")
|
| 55 |
+
return True
|
| 56 |
+
|
| 57 |
+
except Exception as e:
|
| 58 |
+
st.error(f"Database initialization error: {str(e)}")
|
| 59 |
+
import traceback
|
| 60 |
+
st.error(f"Detailed error: {traceback.format_exc()}")
|
| 61 |
+
return False
|
| 62 |
|
| 63 |
def display_example_questions():
|
| 64 |
examples = [
|