Update app.py
Browse files
app.py
CHANGED
@@ -124,11 +124,8 @@ def load_qa_history():
|
|
124 |
def save_qa_history(history_entry):
|
125 |
"""Save QA history entry to local JSON file"""
|
126 |
try:
|
127 |
-
# Define the local path where you want to save the
|
128 |
-
local_path = Path("
|
129 |
-
|
130 |
-
# Create the directory if it doesn't exist
|
131 |
-
local_path.parent.mkdir(parents=True, exist_ok=True)
|
132 |
|
133 |
# Initialize or load existing history
|
134 |
if local_path.exists():
|
@@ -147,10 +144,11 @@ def save_qa_history(history_entry):
|
|
147 |
with open(local_path, "w", encoding="utf-8") as f:
|
148 |
json.dump(history_data, f, ensure_ascii=False, indent=2)
|
149 |
|
|
|
|
|
150 |
except Exception as e:
|
151 |
st.error(f"Error saving QA history: {str(e)}")
|
152 |
|
153 |
-
|
154 |
def add_to_qa_history(query: str, answer: str):
|
155 |
"""Add new QA pair to history"""
|
156 |
history_entry = {
|
@@ -165,12 +163,14 @@ def add_to_qa_history(query: str, answer: str):
|
|
165 |
def clear_qa_history():
|
166 |
"""Clear QA history file"""
|
167 |
try:
|
168 |
-
local_path = Path("
|
169 |
|
170 |
# Write empty list to history file
|
171 |
with open(local_path, "w", encoding="utf-8") as f:
|
172 |
json.dump([], f, ensure_ascii=False, indent=2)
|
173 |
|
|
|
|
|
174 |
except Exception as e:
|
175 |
st.error(f"Error clearing QA history: {str(e)}")
|
176 |
|
|
|
124 |
def save_qa_history(history_entry):
|
125 |
"""Save QA history entry to local JSON file"""
|
126 |
try:
|
127 |
+
# Define the local path where you want to save the file
|
128 |
+
local_path = Path.home() / "Downloads" / "qa_history.json"
|
|
|
|
|
|
|
129 |
|
130 |
# Initialize or load existing history
|
131 |
if local_path.exists():
|
|
|
144 |
with open(local_path, "w", encoding="utf-8") as f:
|
145 |
json.dump(history_data, f, ensure_ascii=False, indent=2)
|
146 |
|
147 |
+
st.success(f"Successfully saved QA history to {local_path}")
|
148 |
+
|
149 |
except Exception as e:
|
150 |
st.error(f"Error saving QA history: {str(e)}")
|
151 |
|
|
|
152 |
def add_to_qa_history(query: str, answer: str):
|
153 |
"""Add new QA pair to history"""
|
154 |
history_entry = {
|
|
|
163 |
def clear_qa_history():
|
164 |
"""Clear QA history file"""
|
165 |
try:
|
166 |
+
local_path = Path.home() / "Downloads" / "qa_history.json"
|
167 |
|
168 |
# Write empty list to history file
|
169 |
with open(local_path, "w", encoding="utf-8") as f:
|
170 |
json.dump([], f, ensure_ascii=False, indent=2)
|
171 |
|
172 |
+
st.success(f"Successfully cleared QA history at {local_path}")
|
173 |
+
|
174 |
except Exception as e:
|
175 |
st.error(f"Error clearing QA history: {str(e)}")
|
176 |
|