Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
@@ -8,6 +8,18 @@ st.set_page_config(page_title="Indian Spiritual RAG")
|
|
8 |
from rag_engine import process_query, load_model
|
9 |
from utils import setup_all_auth
|
10 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
11 |
# Display title with custom styling
|
12 |
st.markdown("""
|
13 |
<style>
|
@@ -21,7 +33,17 @@ st.markdown("""
|
|
21 |
border: 2px solid #FF5722 !important;
|
22 |
border-radius: 8px !important;
|
23 |
}
|
24 |
-
/*
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
25 |
.stTextInput>div>div>input {
|
26 |
border: 2px solid #4CAF50 !important;
|
27 |
border-radius: 8px !important;
|
@@ -30,37 +52,44 @@ st.markdown("""
|
|
30 |
</style>
|
31 |
|
32 |
<script>
|
33 |
-
// Run once DOM is fully loaded
|
34 |
document.addEventListener('DOMContentLoaded', function() {
|
35 |
-
|
36 |
-
function addInputEvents() {
|
37 |
-
// Find all input elements in text inputs
|
38 |
const inputs = document.querySelectorAll('.stTextInput input');
|
39 |
|
40 |
inputs.forEach(function(input) {
|
41 |
-
//
|
42 |
-
input.
|
43 |
-
|
44 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
45 |
});
|
46 |
|
47 |
-
// Blur
|
48 |
-
|
49 |
-
this.style.border = '2px solid #4CAF50
|
50 |
-
this.style.
|
|
|
51 |
});
|
52 |
});
|
53 |
}
|
54 |
|
55 |
-
//
|
56 |
-
|
57 |
|
58 |
-
// Watch for changes
|
59 |
const observer = new MutationObserver(function() {
|
60 |
-
|
61 |
});
|
62 |
|
63 |
-
// Start observing
|
64 |
observer.observe(document.body, {
|
65 |
childList: true,
|
66 |
subtree: true
|
@@ -71,47 +100,40 @@ document.addEventListener('DOMContentLoaded', function() {
|
|
71 |
<div class="main-title">Indian Spiritual Texts Q&A</div>
|
72 |
""", unsafe_allow_html=True)
|
73 |
|
74 |
-
# Initialize session state
|
75 |
-
if 'initialized' not in st.session_state:
|
76 |
-
st.session_state.initialized = False
|
77 |
-
if 'last_query' not in st.session_state:
|
78 |
-
st.session_state.last_query = ""
|
79 |
-
if 'submit_clicked' not in st.session_state:
|
80 |
-
st.session_state.submit_clicked = False
|
81 |
-
if 'init_start_time' not in st.session_state:
|
82 |
-
st.session_state.init_start_time = None
|
83 |
-
|
84 |
# Create placeholder for initialization message
|
85 |
init_message = st.empty()
|
86 |
|
87 |
-
# Handle initialization
|
88 |
if not st.session_state.initialized:
|
|
|
|
|
|
|
89 |
try:
|
90 |
-
# Show the loading message
|
91 |
-
init_message.info("Hang in there! We are setting the system up for you. 😊")
|
92 |
-
|
93 |
-
# Record start time
|
94 |
-
st.session_state.init_start_time = time.time()
|
95 |
-
|
96 |
# Setup authentication
|
97 |
setup_all_auth()
|
98 |
|
99 |
-
# Force model loading
|
100 |
load_model()
|
101 |
|
102 |
# Mark as initialized
|
103 |
st.session_state.initialized = True
|
104 |
|
|
|
|
|
|
|
|
|
105 |
# Show success message
|
106 |
init_message.success("System initialized successfully!")
|
107 |
except Exception as e:
|
108 |
-
|
109 |
-
st.
|
110 |
-
|
111 |
-
|
112 |
-
|
113 |
-
|
114 |
-
st.session_state.
|
|
|
|
|
115 |
|
116 |
# Function to process when enter is pressed or button is clicked
|
117 |
def process_input():
|
|
|
8 |
from rag_engine import process_query, load_model
|
9 |
from utils import setup_all_auth
|
10 |
|
11 |
+
# Initialize session state variables (at the very top)
|
12 |
+
if 'initialized' not in st.session_state:
|
13 |
+
st.session_state.initialized = False
|
14 |
+
if 'last_query' not in st.session_state:
|
15 |
+
st.session_state.last_query = ""
|
16 |
+
if 'submit_clicked' not in st.session_state:
|
17 |
+
st.session_state.submit_clicked = False
|
18 |
+
if 'show_success' not in st.session_state:
|
19 |
+
st.session_state.show_success = False
|
20 |
+
if 'success_time' not in st.session_state:
|
21 |
+
st.session_state.success_time = None
|
22 |
+
|
23 |
# Display title with custom styling
|
24 |
st.markdown("""
|
25 |
<style>
|
|
|
33 |
border: 2px solid #FF5722 !important;
|
34 |
border-radius: 8px !important;
|
35 |
}
|
36 |
+
/* Remove any default styling for input fields */
|
37 |
+
div[data-baseweb="input"] {
|
38 |
+
border: none !important;
|
39 |
+
box-shadow: none !important;
|
40 |
+
}
|
41 |
+
div[data-baseweb="input"] > div {
|
42 |
+
background-color: transparent !important;
|
43 |
+
}
|
44 |
+
div[data-baseweb="input"] > div > div {
|
45 |
+
box-shadow: none !important;
|
46 |
+
}
|
47 |
.stTextInput>div>div>input {
|
48 |
border: 2px solid #4CAF50 !important;
|
49 |
border-radius: 8px !important;
|
|
|
52 |
</style>
|
53 |
|
54 |
<script>
|
|
|
55 |
document.addEventListener('DOMContentLoaded', function() {
|
56 |
+
function applyInputStyles() {
|
|
|
|
|
57 |
const inputs = document.querySelectorAll('.stTextInput input');
|
58 |
|
59 |
inputs.forEach(function(input) {
|
60 |
+
// Clean up old event listeners if any
|
61 |
+
const newInput = input.cloneNode(true);
|
62 |
+
input.parentNode.replaceChild(newInput, input);
|
63 |
+
|
64 |
+
// Set initial green border
|
65 |
+
newInput.style.border = '2px solid #4CAF50';
|
66 |
+
newInput.style.borderRadius = '8px';
|
67 |
+
newInput.style.boxShadow = 'none';
|
68 |
+
|
69 |
+
// Focus - change to red
|
70 |
+
newInput.addEventListener('focus', function() {
|
71 |
+
this.style.border = '2px solid #FF5722';
|
72 |
+
this.style.borderRadius = '8px';
|
73 |
+
this.style.boxShadow = 'none';
|
74 |
});
|
75 |
|
76 |
+
// Blur - back to green
|
77 |
+
newInput.addEventListener('blur', function() {
|
78 |
+
this.style.border = '2px solid #4CAF50';
|
79 |
+
this.style.borderRadius = '8px';
|
80 |
+
this.style.boxShadow = 'none';
|
81 |
});
|
82 |
});
|
83 |
}
|
84 |
|
85 |
+
// Run initially
|
86 |
+
applyInputStyles();
|
87 |
|
88 |
+
// Watch for changes
|
89 |
const observer = new MutationObserver(function() {
|
90 |
+
applyInputStyles();
|
91 |
});
|
92 |
|
|
|
93 |
observer.observe(document.body, {
|
94 |
childList: true,
|
95 |
subtree: true
|
|
|
100 |
<div class="main-title">Indian Spiritual Texts Q&A</div>
|
101 |
""", unsafe_allow_html=True)
|
102 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
103 |
# Create placeholder for initialization message
|
104 |
init_message = st.empty()
|
105 |
|
106 |
+
# Handle initialization only once
|
107 |
if not st.session_state.initialized:
|
108 |
+
# Show the loading message
|
109 |
+
init_message.info("Hang in there! We are setting the system up for you. 😊")
|
110 |
+
|
111 |
try:
|
|
|
|
|
|
|
|
|
|
|
|
|
112 |
# Setup authentication
|
113 |
setup_all_auth()
|
114 |
|
115 |
+
# Force model loading
|
116 |
load_model()
|
117 |
|
118 |
# Mark as initialized
|
119 |
st.session_state.initialized = True
|
120 |
|
121 |
+
# Set flags to show success message temporarily
|
122 |
+
st.session_state.show_success = True
|
123 |
+
st.session_state.success_time = time.time()
|
124 |
+
|
125 |
# Show success message
|
126 |
init_message.success("System initialized successfully!")
|
127 |
except Exception as e:
|
128 |
+
init_message.error(f"Error initializing: {str(e)}")
|
129 |
+
st.stop() # Stop execution if initialization fails
|
130 |
+
else:
|
131 |
+
# Check if we need to clear the success message
|
132 |
+
current_time = time.time()
|
133 |
+
if st.session_state.show_success:
|
134 |
+
if current_time - st.session_state.success_time > 2:
|
135 |
+
init_message.empty()
|
136 |
+
st.session_state.show_success = False
|
137 |
|
138 |
# Function to process when enter is pressed or button is clicked
|
139 |
def process_input():
|