Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -52,7 +52,7 @@ class Chatbot:
|
|
52 |
# access chat log file in data folder (persistent storage)
|
53 |
dataset_dir = Path("logs")
|
54 |
dataset_dir.mkdir(parents=True, exist_ok=True)
|
55 |
-
self.
|
56 |
#self.history_file = f"chat_log_{uuid.uuid4()}.json"
|
57 |
|
58 |
#scheduler = CommitScheduler(
|
@@ -72,12 +72,12 @@ class Chatbot:
|
|
72 |
return message
|
73 |
|
74 |
# do not need this function if use append mode when dump data in file
|
75 |
-
def load_chat_history(self):
|
76 |
-
|
77 |
-
|
78 |
-
|
79 |
-
|
80 |
-
|
81 |
|
82 |
def append_chat_history(self, user_input, output):
|
83 |
# append chat history
|
@@ -103,7 +103,7 @@ class Chatbot:
|
|
103 |
|
104 |
def save_chat_history(self):
|
105 |
with scheduler.lock:
|
106 |
-
with self.
|
107 |
json.dump(self.chat_history, f)
|
108 |
f.write("\n")
|
109 |
|
|
|
52 |
# access chat log file in data folder (persistent storage)
|
53 |
dataset_dir = Path("logs")
|
54 |
dataset_dir.mkdir(parents=True, exist_ok=True)
|
55 |
+
self.dataset_path = dataset_dir / f"chat_log_{uuid4()}.json"
|
56 |
#self.history_file = f"chat_log_{uuid.uuid4()}.json"
|
57 |
|
58 |
#scheduler = CommitScheduler(
|
|
|
72 |
return message
|
73 |
|
74 |
# do not need this function if use append mode when dump data in file
|
75 |
+
#def load_chat_history(self):
|
76 |
+
# try:
|
77 |
+
# with open(self.dataset_path, 'r') as f:
|
78 |
+
# self.chat_history = json.load(f)
|
79 |
+
# except FileNotFoundError:
|
80 |
+
# pass
|
81 |
|
82 |
def append_chat_history(self, user_input, output):
|
83 |
# append chat history
|
|
|
103 |
|
104 |
def save_chat_history(self):
|
105 |
with scheduler.lock:
|
106 |
+
with self.dataset_path.open("a") as f:
|
107 |
json.dump(self.chat_history, f)
|
108 |
f.write("\n")
|
109 |
|