Update app.py
Browse files
app.py
CHANGED
@@ -18,6 +18,7 @@ from transformers import AutoModelForCausalLM, AutoTokenizer
|
|
18 |
import torch
|
19 |
import os
|
20 |
import requests
|
|
|
21 |
#HF_TOKEN = os.getenv("HF_TOKEN")
|
22 |
|
23 |
API_KEY = os.environ.get("OPENROUTER_API_KEY")
|
@@ -270,6 +271,14 @@ def chatbot(query):
|
|
270 |
#demo.launch(share=False)
|
271 |
# Initialize chat history with a welcome message
|
272 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
273 |
def ask(user_message, chat_history):
|
274 |
if not user_message:
|
275 |
return chat_history, chat_history, ""
|
|
|
18 |
import torch
|
19 |
import os
|
20 |
import requests
|
21 |
+
import time
|
22 |
#HF_TOKEN = os.getenv("HF_TOKEN")
|
23 |
|
24 |
API_KEY = os.environ.get("OPENROUTER_API_KEY")
|
|
|
271 |
#demo.launch(share=False)
|
272 |
# Initialize chat history with a welcome message
|
273 |
|
274 |
+
|
275 |
+
def save_chat_to_file(chat_history):
|
276 |
+
timestamp = time.strftime("%Y%m%d-%H%M%S") # Create a timestamp like 20250430-141522
|
277 |
+
filename = f"chat_history_{timestamp}.json" # Unique filename
|
278 |
+
with open(filename, "w", encoding="utf-8") as f:
|
279 |
+
json.dump(chat_history, f, ensure_ascii=False, indent=2)
|
280 |
+
print(f"Chat history saved to {filename}")
|
281 |
+
|
282 |
def ask(user_message, chat_history):
|
283 |
if not user_message:
|
284 |
return chat_history, chat_history, ""
|