JirasakJo commited on
Commit
3ec547a
·
verified ·
1 Parent(s): 9ce6618

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +37 -7
app.py CHANGED
@@ -1,6 +1,9 @@
1
  import streamlit as st
2
  import json
3
  import os
 
 
 
4
  from datetime import datetime, timedelta
5
  import subprocess
6
  from huggingface_hub import HfApi
@@ -120,15 +123,42 @@ def initialize_pipeline():
120
  return None
121
 
122
  def load_qa_history():
123
- """Load QA history from local JSON file"""
124
  try:
125
- history_file = Path("qa_history.json")
126
- if history_file.exists():
127
- with open(history_file, "r", encoding="utf-8") as f:
128
- return json.load(f)
129
- return []
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
130
  except Exception as e:
131
- st.error(f"Error loading QA history: {str(e)}")
132
  return []
133
 
134
  def save_qa_history(history_entry):
 
1
  import streamlit as st
2
  import json
3
  import os
4
+ import requests
5
+ import json
6
+ import base64
7
  from datetime import datetime, timedelta
8
  import subprocess
9
  from huggingface_hub import HfApi
 
123
  return None
124
 
125
  def load_qa_history():
126
+ """Load QA history directly from GitHub repository"""
127
  try:
128
+ import requests
129
+ import base64
130
+ import json
131
+
132
+ # GitHub API configuration
133
+ REPO_OWNER = "jirasaksaimekJijo"
134
+ REPO_NAME = "swu-chat-bot-project"
135
+ FILE_PATH = "qa_history.json"
136
+ GITHUB_TOKEN = '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'
137
+
138
+ # Set up GitHub API request
139
+ api_url = f"https://api.github.com/repos/{REPO_OWNER}/{REPO_NAME}/contents/{FILE_PATH}"
140
+ headers = {"Accept": "application/vnd.github.v3+json"}
141
+
142
+ if GITHUB_TOKEN:
143
+ headers["Authorization"] = f"token {GITHUB_TOKEN}"
144
+
145
+ # Make the request to GitHub API
146
+ response = requests.get(api_url, headers=headers)
147
+
148
+ if response.status_code == 200:
149
+ # Decode the content from base64
150
+ content_data = response.json()
151
+ file_content = base64.b64decode(content_data["content"]).decode("utf-8")
152
+ # Parse JSON
153
+ history_data = json.loads(file_content)
154
+ return history_data
155
+ else:
156
+ st.warning(f"Failed to fetch QA history: {response.status_code} - {response.reason}")
157
+ # Return empty list if file doesn't exist or can't be accessed
158
+ return []
159
+
160
  except Exception as e:
161
+ st.error(f"Error loading QA history from GitHub: {str(e)}")
162
  return []
163
 
164
  def save_qa_history(history_entry):