ankanghosh commited on
Commit
1a4c2ba
·
verified ·
1 Parent(s): d2770d0

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +30 -19
app.py CHANGED
@@ -21,12 +21,10 @@ st.markdown("""
21
  border: 2px solid #FF5722 !important;
22
  border-radius: 8px !important;
23
  }
24
- /* Override Streamlit's default input styling */
25
  div[data-baseweb="input"] {
26
- border-radius: 8px;
27
- }
28
- div[data-baseweb="input"] > div {
29
- background-color: transparent;
30
  }
31
  </style>
32
 
@@ -40,16 +38,17 @@ document.addEventListener('DOMContentLoaded', function() {
40
  input.removeEventListener('focus', onFocus);
41
  input.removeEventListener('blur', onBlur);
42
 
43
- // Set initial style (green)
44
  const parent = input.closest('div[data-baseweb="input"]');
45
  if (parent) {
 
46
  parent.style.border = '2px solid #4CAF50';
47
- parent.style.boxShadow = 'none';
 
 
 
 
48
  }
49
-
50
- // Add new listeners
51
- input.addEventListener('focus', onFocus);
52
- input.addEventListener('blur', onBlur);
53
  });
54
  }
55
 
@@ -57,7 +56,6 @@ document.addEventListener('DOMContentLoaded', function() {
57
  const parent = event.target.closest('div[data-baseweb="input"]');
58
  if (parent) {
59
  parent.style.border = '2px solid #FF5722';
60
- parent.style.boxShadow = 'none';
61
  }
62
  }
63
 
@@ -65,7 +63,6 @@ document.addEventListener('DOMContentLoaded', function() {
65
  const parent = event.target.closest('div[data-baseweb="input"]');
66
  if (parent) {
67
  parent.style.border = '2px solid #4CAF50';
68
- parent.style.boxShadow = 'none';
69
  }
70
  }
71
 
@@ -94,6 +91,10 @@ if 'last_query' not in st.session_state:
94
  st.session_state.last_query = ""
95
  if 'submit_clicked' not in st.session_state:
96
  st.session_state.submit_clicked = False
 
 
 
 
97
 
98
  # Setup all authentication
99
  if not st.session_state.initialized:
@@ -102,23 +103,33 @@ if not st.session_state.initialized:
102
  except Exception as e:
103
  st.error(f"Authentication error: {str(e)}")
104
 
105
- # Preload the model to avoid session state issues
 
 
 
106
  if not st.session_state.initialized:
107
  try:
108
- init_message = st.empty()
109
  init_message.info("Hang in there! We are setting the system up for you. 😊")
110
 
111
- # Force model loading at startup to avoid session state issues
112
  load_model()
113
 
114
- # First set initialized to True
115
  st.session_state.initialized = True
 
116
 
117
- # Then keep the message for 2 seconds before replacing it
118
- time.sleep(2)
119
  init_message.success("System initialized successfully!")
 
120
  except Exception as e:
121
  st.error(f"Error initializing: {str(e)}")
 
 
 
 
 
 
122
 
123
  # Function to process when enter is pressed or button is clicked
124
  def process_input():
 
21
  border: 2px solid #FF5722 !important;
22
  border-radius: 8px !important;
23
  }
24
+ /* Set default green border for all input fields */
25
  div[data-baseweb="input"] {
26
+ border: 2px solid #4CAF50 !important;
27
+ border-radius: 8px !important;
 
 
28
  }
29
  </style>
30
 
 
38
  input.removeEventListener('focus', onFocus);
39
  input.removeEventListener('blur', onBlur);
40
 
41
+ // Get the parent which holds the visible border
42
  const parent = input.closest('div[data-baseweb="input"]');
43
  if (parent) {
44
+ // Force the initial green style
45
  parent.style.border = '2px solid #4CAF50';
46
+ parent.style.borderRadius = '8px';
47
+
48
+ // Add new listeners
49
+ input.addEventListener('focus', onFocus);
50
+ input.addEventListener('blur', onBlur);
51
  }
 
 
 
 
52
  });
53
  }
54
 
 
56
  const parent = event.target.closest('div[data-baseweb="input"]');
57
  if (parent) {
58
  parent.style.border = '2px solid #FF5722';
 
59
  }
60
  }
61
 
 
63
  const parent = event.target.closest('div[data-baseweb="input"]');
64
  if (parent) {
65
  parent.style.border = '2px solid #4CAF50';
 
66
  }
67
  }
68
 
 
91
  st.session_state.last_query = ""
92
  if 'submit_clicked' not in st.session_state:
93
  st.session_state.submit_clicked = False
94
+ if 'init_time' not in st.session_state:
95
+ st.session_state.init_time = None
96
+ if 'success_shown' not in st.session_state:
97
+ st.session_state.success_shown = False
98
 
99
  # Setup all authentication
100
  if not st.session_state.initialized:
 
103
  except Exception as e:
104
  st.error(f"Authentication error: {str(e)}")
105
 
106
+ # Create a placeholder for initialization messages
107
+ init_message = st.empty()
108
+
109
+ # Handle initialization
110
  if not st.session_state.initialized:
111
  try:
112
+ # Show the loading message
113
  init_message.info("Hang in there! We are setting the system up for you. 😊")
114
 
115
+ # Load the model
116
  load_model()
117
 
118
+ # Mark as initialized and record the time
119
  st.session_state.initialized = True
120
+ st.session_state.init_time = time.time()
121
 
122
+ # Show success message (will be removed later)
 
123
  init_message.success("System initialized successfully!")
124
+ st.session_state.success_shown = True
125
  except Exception as e:
126
  st.error(f"Error initializing: {str(e)}")
127
+ else:
128
+ # Check if we need to clear the success message
129
+ if st.session_state.success_shown and st.session_state.init_time is not None:
130
+ if time.time() - st.session_state.init_time > 2:
131
+ init_message.empty()
132
+ st.session_state.success_shown = False
133
 
134
  # Function to process when enter is pressed or button is clicked
135
  def process_input():