stevafernandes commited on
Commit
2a7e16d
·
verified ·
1 Parent(s): ff615b6

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +153 -29
app.py CHANGED
@@ -115,34 +115,150 @@ def initialize_vector_store(_api_key):
115
 
116
 
117
  def main():
118
- st.set_page_config(page_title="Papal Encyclicals RAG", page_icon="📄", layout="centered")
 
 
 
 
 
119
 
120
- # Custom CSS for white background and black text
121
  st.markdown(
122
  """
123
  <style>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
124
  .stApp {
125
- background-color: white;
126
- color: black;
127
  }
128
- .stMarkdown, .stText, p, span, label, h1, h2, h3 {
129
- color: black !important;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
130
  }
 
 
131
  .stTextInput > div > div > input {
132
- color: black;
133
- background-color: white;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
134
  }
135
- .stSpinner > div > div {
136
- color: black;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
137
  }
138
  </style>
139
  """,
140
  unsafe_allow_html=True
141
  )
142
 
143
- st.header("Papal Encyclicals RAG")
144
- st.markdown("")
145
- st.markdown("---")
146
 
147
  # Check for API key
148
  api_key = GOOGLE_API_KEY
@@ -159,40 +275,48 @@ def main():
159
  st.stop()
160
 
161
  # Initialize vector store (cached, runs only once)
162
- with st.spinner("Loading document... Please wait."):
163
  success, message = initialize_vector_store(api_key)
164
 
165
  if not success:
166
  st.error(message)
167
  st.stop()
168
 
169
- # Display success status
170
- st.success(f"Document loaded: {PDF_FILE_PATH}")
 
 
 
 
 
 
 
 
171
 
172
  # Question input
173
- st.subheader("Ask a question related to papal encyclicals.")
174
  user_question = st.text_input(
175
- "Enter your question about papal encyclicals:",
176
- placeholder="e.g., What are the main topics discussed?",
177
- help="The AI will only answer based on the content of the uploaded PDF"
 
178
  )
179
 
180
  if user_question:
181
  with st.spinner("Searching for answer..."):
182
  try:
183
  answer = user_input(user_question, api_key)
184
- st.markdown("### Answer:")
185
- st.write(answer)
 
 
 
 
 
 
 
186
  except Exception as e:
187
  st.error(f"Error getting answer: {str(e)}")
188
 
189
- # Footer
190
- st.markdown("---")
191
- st.markdown(
192
- "<div style='text-align: center'><small></small></div>",
193
- unsafe_allow_html=True
194
- )
195
-
196
 
197
  if __name__ == "__main__":
198
  main()
 
115
 
116
 
117
  def main():
118
+ st.set_page_config(
119
+ page_title="Papal Encyclicals RAG",
120
+ page_icon="📄",
121
+ layout="centered",
122
+ initial_sidebar_state="collapsed"
123
+ )
124
 
125
+ # Custom CSS for clean, professional appearance
126
  st.markdown(
127
  """
128
  <style>
129
+ /* Hide Streamlit header, footer, and menu */
130
+ #MainMenu {visibility: hidden;}
131
+ header {visibility: hidden;}
132
+ footer {visibility: hidden;}
133
+ .stDeployButton {display: none;}
134
+
135
+ /* Remove top padding caused by hidden header */
136
+ .block-container {
137
+ padding-top: 2rem;
138
+ padding-bottom: 2rem;
139
+ max-width: 800px;
140
+ }
141
+
142
+ /* Clean white background */
143
  .stApp {
144
+ background-color: #ffffff;
 
145
  }
146
+
147
+ /* Typography */
148
+ .main-title {
149
+ font-size: 2.5rem;
150
+ font-weight: 600;
151
+ color: #1a1a1a;
152
+ text-align: center;
153
+ margin-bottom: 0.5rem;
154
+ padding-top: 1rem;
155
+ }
156
+
157
+ .subtitle {
158
+ font-size: 1rem;
159
+ color: #666666;
160
+ text-align: center;
161
+ margin-bottom: 2rem;
162
+ }
163
+
164
+ /* Success message styling */
165
+ .stSuccess {
166
+ background-color: #f0f9f4;
167
+ border: 1px solid #86efac;
168
+ border-radius: 8px;
169
+ padding: 0.75rem 1rem;
170
  }
171
+
172
+ /* Input field styling */
173
  .stTextInput > div > div > input {
174
+ border: 1px solid #e0e0e0;
175
+ border-radius: 8px;
176
+ padding: 0.75rem 1rem;
177
+ font-size: 1rem;
178
+ transition: border-color 0.2s ease;
179
+ }
180
+
181
+ .stTextInput > div > div > input:focus {
182
+ border-color: #4a90d9;
183
+ box-shadow: 0 0 0 2px rgba(74, 144, 217, 0.1);
184
+ }
185
+
186
+ /* Section headers */
187
+ .section-header {
188
+ font-size: 1.1rem;
189
+ font-weight: 500;
190
+ color: #333333;
191
+ margin-top: 1.5rem;
192
+ margin-bottom: 1rem;
193
+ }
194
+
195
+ /* Answer box styling */
196
+ .answer-container {
197
+ background-color: #fafafa;
198
+ border: 1px solid #e8e8e8;
199
+ border-radius: 10px;
200
+ padding: 1.5rem;
201
+ margin-top: 1rem;
202
+ }
203
+
204
+ .answer-label {
205
+ font-size: 0.85rem;
206
+ font-weight: 600;
207
+ color: #888888;
208
+ text-transform: uppercase;
209
+ letter-spacing: 0.5px;
210
+ margin-bottom: 0.75rem;
211
  }
212
+
213
+ .answer-text {
214
+ font-size: 1rem;
215
+ color: #333333;
216
+ line-height: 1.7;
217
+ }
218
+
219
+ /* Divider */
220
+ hr {
221
+ border: none;
222
+ border-top: 1px solid #eaeaea;
223
+ margin: 1.5rem 0;
224
+ }
225
+
226
+ /* Status indicator */
227
+ .status-badge {
228
+ display: inline-flex;
229
+ align-items: center;
230
+ gap: 0.5rem;
231
+ background-color: #f0f9f4;
232
+ color: #166534;
233
+ padding: 0.5rem 1rem;
234
+ border-radius: 20px;
235
+ font-size: 0.9rem;
236
+ font-weight: 500;
237
+ margin-bottom: 2rem;
238
+ }
239
+
240
+ .status-dot {
241
+ width: 8px;
242
+ height: 8px;
243
+ background-color: #22c55e;
244
+ border-radius: 50%;
245
+ }
246
+
247
+ /* Hide label for cleaner look */
248
+ .stTextInput label {
249
+ font-size: 0.95rem;
250
+ color: #444444;
251
+ font-weight: 500;
252
+ margin-bottom: 0.5rem;
253
  }
254
  </style>
255
  """,
256
  unsafe_allow_html=True
257
  )
258
 
259
+ # Header
260
+ st.markdown('<h1 class="main-title">Papal Encyclicals RAG</h1>', unsafe_allow_html=True)
261
+ st.markdown('<p class="subtitle">Ask questions about papal encyclicals and get answers based on the source document</p>', unsafe_allow_html=True)
262
 
263
  # Check for API key
264
  api_key = GOOGLE_API_KEY
 
275
  st.stop()
276
 
277
  # Initialize vector store (cached, runs only once)
278
+ with st.spinner("Loading document..."):
279
  success, message = initialize_vector_store(api_key)
280
 
281
  if not success:
282
  st.error(message)
283
  st.stop()
284
 
285
+ # Display status badge
286
+ st.markdown(
287
+ f'''
288
+ <div class="status-badge">
289
+ <span class="status-dot"></span>
290
+ Document loaded: {PDF_FILE_PATH}
291
+ </div>
292
+ ''',
293
+ unsafe_allow_html=True
294
+ )
295
 
296
  # Question input
 
297
  user_question = st.text_input(
298
+ "Your question",
299
+ placeholder="e.g., What are the main themes discussed in the encyclicals?",
300
+ help="The AI will only answer based on the content of the uploaded PDF",
301
+ label_visibility="visible"
302
  )
303
 
304
  if user_question:
305
  with st.spinner("Searching for answer..."):
306
  try:
307
  answer = user_input(user_question, api_key)
308
+ st.markdown(
309
+ f'''
310
+ <div class="answer-container">
311
+ <div class="answer-label">Answer</div>
312
+ <div class="answer-text">{answer}</div>
313
+ </div>
314
+ ''',
315
+ unsafe_allow_html=True
316
+ )
317
  except Exception as e:
318
  st.error(f"Error getting answer: {str(e)}")
319
 
 
 
 
 
 
 
 
320
 
321
  if __name__ == "__main__":
322
  main()