Spaces:
Paused
Paused
Update app.py
Browse files
app.py
CHANGED
|
@@ -41,30 +41,24 @@ if torch.cuda.is_available():
|
|
| 41 |
tokenizer.pad_token = tokenizer.eos_token
|
| 42 |
|
| 43 |
def save_chat_history(chat_history):
|
| 44 |
-
# Ensure the directory exists
|
| 45 |
-
os.makedirs(os.path.dirname('data/'), exist_ok=True)
|
| 46 |
-
file_path = 'data/chat_history.json'
|
| 47 |
|
| 48 |
-
|
|
|
|
| 49 |
conversation_id = str(uuid.uuid4())
|
| 50 |
|
| 51 |
-
# Prepare the conversation entry
|
| 52 |
conversation_entry = {
|
| 53 |
"id": conversation_id,
|
| 54 |
"chat_history": chat_history
|
| 55 |
}
|
| 56 |
|
| 57 |
-
# Load existing data if the file exists
|
| 58 |
if os.path.exists(file_path):
|
| 59 |
with open(file_path, 'r') as file:
|
| 60 |
data = json.load(file)
|
| 61 |
else:
|
| 62 |
data = []
|
| 63 |
|
| 64 |
-
# Append the new conversation entry
|
| 65 |
data.append(conversation_entry)
|
| 66 |
|
| 67 |
-
# Save the updated data back to the file
|
| 68 |
with open(file_path, 'w') as file:
|
| 69 |
json.dump(data, file, indent=4)
|
| 70 |
|
|
|
|
| 41 |
tokenizer.pad_token = tokenizer.eos_token
|
| 42 |
|
| 43 |
def save_chat_history(chat_history):
|
|
|
|
|
|
|
|
|
|
| 44 |
|
| 45 |
+
file_path = 'chat_history.json'
|
| 46 |
+
|
| 47 |
conversation_id = str(uuid.uuid4())
|
| 48 |
|
|
|
|
| 49 |
conversation_entry = {
|
| 50 |
"id": conversation_id,
|
| 51 |
"chat_history": chat_history
|
| 52 |
}
|
| 53 |
|
|
|
|
| 54 |
if os.path.exists(file_path):
|
| 55 |
with open(file_path, 'r') as file:
|
| 56 |
data = json.load(file)
|
| 57 |
else:
|
| 58 |
data = []
|
| 59 |
|
|
|
|
| 60 |
data.append(conversation_entry)
|
| 61 |
|
|
|
|
| 62 |
with open(file_path, 'w') as file:
|
| 63 |
json.dump(data, file, indent=4)
|
| 64 |
|