JirasakJo commited on
Commit
7767812
·
verified ·
1 Parent(s): f6384d3

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +19 -83
app.py CHANGED
@@ -1,6 +1,5 @@
1
  import streamlit as st
2
  import json
3
- from datetime import datetime, timedelta
4
  import os
5
  import subprocess # Added missing import
6
  from datetime import datetime
@@ -14,13 +13,6 @@ from calendar_rag import (
14
  def load_custom_css():
15
  st.markdown("""
16
  <style>
17
-
18
- /* Spinner text styling */
19
- .stSpinner > div > div {
20
- color: #000000 !important; /* Change the text color to black */
21
- font-size: 1.2rem; /* Adjust font size if needed */
22
- }
23
-
24
  /* General body styling */
25
  body {
26
  font-family: "Arial", sans-serif !important; /* Clean and readable font */
@@ -47,24 +39,13 @@ def load_custom_css():
47
  border-bottom: 3px solid #1E3A8A; /* Keep a blue line for a clean design */
48
  }
49
 
50
- /* Specific styling for the system status and about system headers */
51
- h3 {
52
- color: #ff0015 !important; /* Default color for all h3 elements */
53
  font-weight: 600 !important;
54
- font-size: 1.6rem !important;
55
  margin-top: 1.5rem !important;
56
  }
57
 
58
- div.status-header {
59
- color: #1E3A8A !important; /* Change the text color for status section */
60
- font-size: 1.4rem !important; /* Adjust font size if necessary */
61
- }
62
-
63
- div.about-header {
64
- color: #ff0015 !important; /* Change the text color for about section */
65
- font-size: 1.4rem !important; /* Adjust font size if necessary */
66
- }
67
-
68
  /* Paragraphs and text */
69
  p, span, li {
70
  font-size: 1.2rem !important; /* Larger font size for regular text */
@@ -214,7 +195,7 @@ def save_feedback_to_json():
214
  def add_feedback(query: str, answer: str, is_correct: bool):
215
  """Add feedback entry to session state and save to JSON and GitHub"""
216
  feedback_entry = {
217
- "timestamp": (datetime.now() + timedelta(hours=7)).isoformat(),
218
  "query": query,
219
  "answer": answer,
220
  "is_correct": is_correct
@@ -228,55 +209,6 @@ def add_feedback(query: str, answer: str, is_correct: bool):
228
  else:
229
  st.warning("Feedback saved locally but not pushed to repository")
230
 
231
- def save_feedback_to_repo(file_path: str) -> bool:
232
- """
233
- Save feedback data to Hugging Face repository using git commands
234
-
235
- Args:
236
- file_path (str): Path to the feedback data JSON file
237
-
238
- Returns:
239
- bool: True if successful, False otherwise
240
- """
241
- try:
242
- # Set git configuration using environment variables
243
- git_email = os.getenv('GIT_EMAIL')
244
- git_username = os.getenv('GIT_USERNAME')
245
- subprocess.run(['git', 'config', '--global', 'user.email', git_email], check=True)
246
- subprocess.run(['git', 'config', '--global', 'user.name', git_username], check=True)
247
-
248
- # Initialize repository if not already initialized
249
- subprocess.run(['git', 'init'], check=True)
250
-
251
- # Add Hugging Face repository as remote
252
- hf_token = os.getenv('HF_TOKEN')
253
- remote_url = f"https://{hf_token}@huggingface.co/spaces/JirasakJo/Questions_Graduate_Studies_Calendar_2024"
254
- try:
255
- subprocess.run(['git', 'remote', 'add', 'origin', remote_url], check=True)
256
- except subprocess.CalledProcessError:
257
- # If remote already exists, update it
258
- subprocess.run(['git', 'remote', 'set-url', 'origin', remote_url], check=True)
259
-
260
- # Stage the feedback file
261
- subprocess.run(['git', 'add', file_path], check=True)
262
-
263
- # Commit changes
264
- commit_message = f"Update feedback data at {datetime.now().isoformat()}"
265
- subprocess.run(['git', 'commit', '-m', commit_message], check=True)
266
-
267
- # Push to repository
268
- # Note: You'll need to set up authentication for this to work
269
- subprocess.run(['git', 'push', '-u', 'origin', 'main'], check=True)
270
-
271
- return True
272
-
273
- except subprocess.CalledProcessError as e:
274
- print(f"Git operation failed: {str(e)}")
275
- return False
276
- except Exception as e:
277
- print(f"Error saving to repository: {str(e)}")
278
- return False
279
-
280
  def evaluate_answer(query: str, answer: str):
281
  """Display evaluation buttons for the answer"""
282
  col1, col2, col3 = st.columns([1, 1, 4])
@@ -393,10 +325,12 @@ def main():
393
  with info_col:
394
  # Enhanced system information section
395
  st.markdown("""
396
- <div class="about-header">
397
  <h3>ℹ️ เกี่ยวกับระบบ</h3>
398
- <p>ระบบนี้ใช้เทคโนโลยี <strong>RAG (Retrieval-Augmented Generation)</strong>
399
- ในการค้นหาและตอบคำถามเกี่ยวกับปฏิทินการศึกษา</p>
 
 
400
  <h4 style="color: #1E3A8A; margin-top: 1rem;">สามารถสอบถามข้อมูลเกี่ยวกับ:</h4>
401
  <ul style="list-style-type: none; padding-left: 0;">
402
  <li>📅 กำหนดการต่างๆ ในปฏิทินการศึกษา</li>
@@ -410,17 +344,19 @@ def main():
410
 
411
  # Enhanced system status section
412
  st.markdown("""
413
- <div class="status-header">
414
  <h3>🔄 สถานะระบบ</h3>
415
- <p><strong>⏰ เวลาปัจจุบัน:</strong><br>
416
- {}</p>
417
- <p><strong>📡 สถานะระบบ:</strong><br>
418
- <span class="status-indicator {}">
419
- {} {}
420
- </span></p>
 
 
421
  </div>
422
  """.format(
423
- (datetime.now() + timedelta(hours=7)).strftime('%Y-%m-%d %H:%M:%S'),
424
  "status-online" if st.session_state.pipeline else "status-offline",
425
  "🟢" if st.session_state.pipeline else "🔴",
426
  "พร้อมใช้งาน" if st.session_state.pipeline else "ไม่พร้อมใช้งาน"
 
1
  import streamlit as st
2
  import json
 
3
  import os
4
  import subprocess # Added missing import
5
  from datetime import datetime
 
13
  def load_custom_css():
14
  st.markdown("""
15
  <style>
 
 
 
 
 
 
 
16
  /* General body styling */
17
  body {
18
  font-family: "Arial", sans-serif !important; /* Clean and readable font */
 
39
  border-bottom: 3px solid #1E3A8A; /* Keep a blue line for a clean design */
40
  }
41
 
42
+ h3, h4 {
43
+ color: #000000; /* Black sub-headers */
 
44
  font-weight: 600 !important;
45
+ font-size: 1.6rem !important; /* Increase font size for sub-headers */
46
  margin-top: 1.5rem !important;
47
  }
48
 
 
 
 
 
 
 
 
 
 
 
49
  /* Paragraphs and text */
50
  p, span, li {
51
  font-size: 1.2rem !important; /* Larger font size for regular text */
 
195
  def add_feedback(query: str, answer: str, is_correct: bool):
196
  """Add feedback entry to session state and save to JSON and GitHub"""
197
  feedback_entry = {
198
+ "timestamp": datetime.now().isoformat(),
199
  "query": query,
200
  "answer": answer,
201
  "is_correct": is_correct
 
209
  else:
210
  st.warning("Feedback saved locally but not pushed to repository")
211
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
212
  def evaluate_answer(query: str, answer: str):
213
  """Display evaluation buttons for the answer"""
214
  col1, col2, col3 = st.columns([1, 1, 4])
 
325
  with info_col:
326
  # Enhanced system information section
327
  st.markdown("""
328
+ <div style="background-color: #F9FAFB; padding: 1.5rem; border-radius: 12px; margin-bottom: 2rem;">
329
  <h3>ℹ️ เกี่ยวกับระบบ</h3>
330
+ <p style="color: #ff0015;">
331
+ ระบบนี้ใช้เทคโนโลยี <strong>RAG (Retrieval-Augmented Generation)</strong>
332
+ ในการค้นหาและตอบคำถามเกี่ยวกับปฏิทินการศึกษา
333
+ </p>
334
  <h4 style="color: #1E3A8A; margin-top: 1rem;">สามารถสอบถามข้อมูลเกี่ยวกับ:</h4>
335
  <ul style="list-style-type: none; padding-left: 0;">
336
  <li>📅 กำหนดการต่างๆ ในปฏิทินการศึกษา</li>
 
344
 
345
  # Enhanced system status section
346
  st.markdown("""
347
+ <div style="background-color: #f9fafb; padding: 1.5rem; border-radius: 12px;">
348
  <h3>🔄 สถานะระบบ</h3>
349
+ <div style="margin-top: 1rem;">
350
+ <p><strong>⏰ เวลาปัจจุบัน:</strong><br>
351
+ {}</p>
352
+ <p><strong>📡 สถานะระบบ:</strong><br>
353
+ <span class="status-indicator {}">
354
+ {} {}
355
+ </span></p>
356
+ </div>
357
  </div>
358
  """.format(
359
+ datetime.now().strftime('%Y-%m-%d %H:%M:%S'),
360
  "status-online" if st.session_state.pipeline else "status-offline",
361
  "🟢" if st.session_state.pipeline else "🔴",
362
  "พร้อมใช้งาน" if st.session_state.pipeline else "ไม่พร้อมใช้งาน"