Update app.py
Browse files
app.py
CHANGED
|
@@ -50,36 +50,39 @@ conn_lock = Lock()
|
|
| 50 |
vectorstore_lock = Lock()
|
| 51 |
|
| 52 |
def initialize_database():
|
| 53 |
-
"""Initialize database
|
| 54 |
try:
|
| 55 |
-
|
| 56 |
-
|
| 57 |
-
|
| 58 |
-
|
| 59 |
-
os.makedirs(data_dir)
|
| 60 |
-
|
| 61 |
-
db_path = os.path.join(data_dir, 'rfp_analysis.db')
|
| 62 |
-
|
| 63 |
-
try:
|
| 64 |
-
with open(db_path, 'a') as f:
|
| 65 |
-
pass
|
| 66 |
-
except IOError as e:
|
| 67 |
-
st.error(f"Failed to access database: {e}")
|
| 68 |
-
return False
|
| 69 |
-
|
| 70 |
-
conn = create_connection(db_path)
|
| 71 |
-
|
| 72 |
-
if conn is not None:
|
| 73 |
-
# Create base tables
|
| 74 |
-
create_tables(conn)
|
| 75 |
-
# Create collection-specific tables
|
| 76 |
-
create_collection_tables(conn)
|
| 77 |
-
st.session_state.db_conn = conn
|
| 78 |
-
return True
|
| 79 |
-
else:
|
| 80 |
-
return False
|
| 81 |
else:
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 82 |
return True
|
|
|
|
|
|
|
|
|
|
|
|
|
| 83 |
|
| 84 |
except Exception as e:
|
| 85 |
st.error(f"Database initialization error: {e}")
|
|
|
|
| 50 |
vectorstore_lock = Lock()
|
| 51 |
|
| 52 |
def initialize_database():
|
| 53 |
+
"""Initialize database with persistent storage."""
|
| 54 |
try:
|
| 55 |
+
if 'db_conn' not in st.session_state:
|
| 56 |
+
# Get storage path
|
| 57 |
+
if os.path.exists('/data'):
|
| 58 |
+
base_path = Path('/data')
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 59 |
else:
|
| 60 |
+
base_path = Path(os.getcwd()) / 'data'
|
| 61 |
+
|
| 62 |
+
# Ensure data directory exists
|
| 63 |
+
base_path.mkdir(parents=True, exist_ok=True)
|
| 64 |
+
|
| 65 |
+
# Create database path
|
| 66 |
+
db_path = base_path / 'rfp_analysis.db'
|
| 67 |
+
|
| 68 |
+
try:
|
| 69 |
+
# Ensure file can be created
|
| 70 |
+
db_path.touch(exist_ok=True)
|
| 71 |
+
except Exception as e:
|
| 72 |
+
st.error(f"Failed to create database file: {e}")
|
| 73 |
+
return False
|
| 74 |
+
|
| 75 |
+
# Create connection
|
| 76 |
+
conn = create_connection(str(db_path))
|
| 77 |
+
if conn is not None:
|
| 78 |
+
# Create all tables (includes collection tables)
|
| 79 |
+
create_tables(conn)
|
| 80 |
+
st.session_state.db_conn = conn
|
| 81 |
return True
|
| 82 |
+
else:
|
| 83 |
+
return False
|
| 84 |
+
else:
|
| 85 |
+
return True
|
| 86 |
|
| 87 |
except Exception as e:
|
| 88 |
st.error(f"Database initialization error: {e}")
|