NavyDevilDoc commited on
Commit
56e4e5f
·
verified ·
1 Parent(s): 260d73e

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +16 -9
app.py CHANGED
@@ -114,25 +114,32 @@ with st.sidebar:
114
  # If the DB has changed or isn't loaded, load it now
115
  if 'current_db_name' not in st.session_state or st.session_state.current_db_name != selected_db:
116
 
117
- # We use an empty container to hold the error if it happens
118
- error_container = st.empty()
119
 
120
- with st.spinner(f"Loading {selected_db} from Cloud..."):
121
 
122
  # 1. Attempt the Pull
123
  result = SyncManager.pull_data(selected_db)
124
 
125
  # 2. Check the Result
126
  if result is True:
127
- # Success! Initialize normally
 
 
 
 
 
 
 
 
 
128
  st.session_state.db = DatabaseManager(selected_db)
129
  st.session_state.search_engine = SearchEngine()
130
  st.session_state.current_db_name = selected_db
131
- st.rerun()
132
- else:
133
- # Failure! Show the error and STOP.
134
- # Do NOT create an empty database. Do NOT rerun.
135
- error_container.error(f"CRITICAL ERROR: Could not load database.\n\nDetails: {result}")
136
  st.stop()
137
 
138
  # 3. Upload Section
 
114
  # If the DB has changed or isn't loaded, load it now
115
  if 'current_db_name' not in st.session_state or st.session_state.current_db_name != selected_db:
116
 
117
+ # We use an empty container to hold messages
118
+ msg_container = st.empty()
119
 
120
+ with st.spinner(f"Syncing {selected_db}..."):
121
 
122
  # 1. Attempt the Pull
123
  result = SyncManager.pull_data(selected_db)
124
 
125
  # 2. Check the Result
126
  if result is True:
127
+ # Success! Cloud file found.
128
+ msg_container.success(f"Loaded {selected_db} from Cloud.")
129
+ else:
130
+ # Failure! (File deleted or new setup)
131
+ # INSTEAD OF STOPPING, we warn and create a fresh local DB.
132
+ msg_container.warning(f"Could not find {selected_db} in cloud. Creating new local database.")
133
+ # We do NOT run st.stop() here anymore.
134
+
135
+ # 3. Initialize the Database Manager (Either with the downloaded file or a new blank one)
136
+ try:
137
  st.session_state.db = DatabaseManager(selected_db)
138
  st.session_state.search_engine = SearchEngine()
139
  st.session_state.current_db_name = selected_db
140
+ # We intentionally do NOT rerun immediately here to let the warning show
141
+ except Exception as e:
142
+ st.error(f"Failed to initialize database: {e}")
 
 
143
  st.stop()
144
 
145
  # 3. Upload Section