Spaces:
Build error
Build error
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,3 +1,5 @@
|
|
|
|
|
|
|
|
| 1 |
import streamlit as st
|
| 2 |
import os
|
| 3 |
import sqlite3
|
|
@@ -10,34 +12,39 @@ from utils.database import (
|
|
| 10 |
create_tables
|
| 11 |
)
|
| 12 |
import time
|
|
|
|
|
|
|
|
|
|
|
|
|
| 13 |
|
| 14 |
def initialize_database():
|
| 15 |
"""Initialize database connection and tables."""
|
| 16 |
try:
|
| 17 |
-
|
| 18 |
-
|
| 19 |
-
|
| 20 |
-
os.
|
| 21 |
-
|
| 22 |
-
|
| 23 |
-
|
| 24 |
-
|
| 25 |
-
|
| 26 |
-
|
| 27 |
-
|
| 28 |
-
|
| 29 |
-
|
| 30 |
-
|
| 31 |
-
|
| 32 |
-
|
| 33 |
-
|
| 34 |
-
|
| 35 |
-
|
|
|
|
|
|
|
|
|
|
| 36 |
else:
|
| 37 |
-
return
|
| 38 |
-
|
| 39 |
-
return True
|
| 40 |
-
|
| 41 |
except Exception:
|
| 42 |
return False
|
| 43 |
|
|
@@ -111,7 +118,7 @@ def main():
|
|
| 111 |
st.session_state.processed_files = uploaded_files
|
| 112 |
st.session_state.chat_ready = True
|
| 113 |
time.sleep(1)
|
| 114 |
-
st.
|
| 115 |
|
| 116 |
# Knowledge Base Status
|
| 117 |
if st.session_state.get('vector_store'):
|
|
@@ -148,4 +155,4 @@ def main():
|
|
| 148 |
display_chat_interface()
|
| 149 |
|
| 150 |
if __name__ == "__main__":
|
| 151 |
-
main()
|
|
|
|
| 1 |
+
# app.py
|
| 2 |
+
|
| 3 |
import streamlit as st
|
| 4 |
import os
|
| 5 |
import sqlite3
|
|
|
|
| 12 |
create_tables
|
| 13 |
)
|
| 14 |
import time
|
| 15 |
+
from threading import Lock
|
| 16 |
+
|
| 17 |
+
# Create a lock for database operations
|
| 18 |
+
conn_lock = Lock()
|
| 19 |
|
| 20 |
def initialize_database():
|
| 21 |
"""Initialize database connection and tables."""
|
| 22 |
try:
|
| 23 |
+
with conn_lock:
|
| 24 |
+
if 'db_conn' not in st.session_state:
|
| 25 |
+
data_dir = "data"
|
| 26 |
+
if not os.path.exists(data_dir):
|
| 27 |
+
os.makedirs(data_dir)
|
| 28 |
+
|
| 29 |
+
db_path = os.path.join(data_dir, 'rfp_analysis.db')
|
| 30 |
+
|
| 31 |
+
try:
|
| 32 |
+
with open(db_path, 'a') as f:
|
| 33 |
+
pass
|
| 34 |
+
except IOError as e:
|
| 35 |
+
return False
|
| 36 |
+
|
| 37 |
+
conn = create_connection(db_path)
|
| 38 |
+
|
| 39 |
+
if conn is not None:
|
| 40 |
+
create_tables(conn)
|
| 41 |
+
st.session_state.db_conn = conn
|
| 42 |
+
return True
|
| 43 |
+
else:
|
| 44 |
+
return False
|
| 45 |
else:
|
| 46 |
+
return True
|
| 47 |
+
|
|
|
|
|
|
|
| 48 |
except Exception:
|
| 49 |
return False
|
| 50 |
|
|
|
|
| 118 |
st.session_state.processed_files = uploaded_files
|
| 119 |
st.session_state.chat_ready = True
|
| 120 |
time.sleep(1)
|
| 121 |
+
st.experimental_rerun()
|
| 122 |
|
| 123 |
# Knowledge Base Status
|
| 124 |
if st.session_state.get('vector_store'):
|
|
|
|
| 155 |
display_chat_interface()
|
| 156 |
|
| 157 |
if __name__ == "__main__":
|
| 158 |
+
main()
|