cryogenic22 commited on
Commit
26bd6f5
·
verified ·
1 Parent(s): bec446c

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +20 -25
app.py CHANGED
@@ -12,54 +12,48 @@ from utils.database import (
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 = [
65
  "📊 Summarize the main points of the document",
@@ -74,9 +68,9 @@ def main():
74
  # Set up the page configuration
75
  st.set_page_config(layout="wide", page_title="SYNAPTYX - RFP Analysis Agent")
76
 
77
- # Initialize database first
78
  if not initialize_database():
79
- st.error("Failed to initialize database. Please check the application logs.")
80
  return
81
 
82
  # Initialize session state for UI control
@@ -120,7 +114,7 @@ def main():
120
  # Main chat area
121
  if not st.session_state.chat_ready:
122
  # Welcome screen
123
- st.title("🤖 SYNAPTYX - RFP Analysis Agent")
124
  st.markdown("### Welcome to your AI-powered RFP analysis assistant!")
125
 
126
  col1, col2 = st.columns(2)
@@ -137,7 +131,8 @@ def main():
137
  for example in display_example_questions():
138
  st.markdown(f"• {example}")
139
  else:
140
- # Clean chat interface
 
141
  display_chat_interface()
142
 
143
  if __name__ == "__main__":
 
12
  import time
13
 
14
  def initialize_database():
15
+ """Initialize database connection and tables."""
16
  try:
17
  if 'db_conn' not in st.session_state:
 
18
  data_dir = "data"
 
 
19
  if not os.path.exists(data_dir):
 
20
  os.makedirs(data_dir)
 
 
 
21
 
 
22
  db_path = os.path.join(data_dir, 'rfp_analysis.db')
 
23
 
 
24
  try:
25
  with open(db_path, 'a') as f:
26
  pass
 
27
  except IOError as e:
 
28
  return False
29
 
30
  conn = create_connection(db_path)
31
 
32
  if conn is not None:
 
33
  create_tables(conn)
34
  st.session_state.db_conn = conn
 
35
  return True
36
  else:
 
37
  return False
38
  else:
 
39
  return True
40
 
41
+ except Exception:
 
 
 
42
  return False
43
 
44
+ def display_header():
45
+ """Display application header with logo."""
46
+ header_col1, header_col2 = st.columns([1, 4])
47
+
48
+ with header_col1:
49
+ if os.path.exists("img/logo.png"):
50
+ st.image("img/logo.png", width=100)
51
+ else:
52
+ st.error("Logo not found at img/logo.png")
53
+
54
+ with header_col2:
55
+ st.title("SYNAPTYX - RFP Analysis Agent")
56
+
57
  def display_example_questions():
58
  examples = [
59
  "📊 Summarize the main points of the document",
 
68
  # Set up the page configuration
69
  st.set_page_config(layout="wide", page_title="SYNAPTYX - RFP Analysis Agent")
70
 
71
+ # Initialize database silently
72
  if not initialize_database():
73
+ st.error("Failed to initialize database. Please contact support.")
74
  return
75
 
76
  # Initialize session state for UI control
 
114
  # Main chat area
115
  if not st.session_state.chat_ready:
116
  # Welcome screen
117
+ display_header()
118
  st.markdown("### Welcome to your AI-powered RFP analysis assistant!")
119
 
120
  col1, col2 = st.columns(2)
 
131
  for example in display_example_questions():
132
  st.markdown(f"• {example}")
133
  else:
134
+ # Display header and chat interface
135
+ display_header()
136
  display_chat_interface()
137
 
138
  if __name__ == "__main__":