Files changed (1) hide show
  1. utils.py +18 -0
utils.py ADDED
@@ -0,0 +1,18 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import json
2
+ import os
3
+ from datetime import datetime
4
+
5
+ def detect_language(text: str) -> str:
6
+ if any(char in 'áéíóúñÁÉÍÓÚÑ¿¡' for char in text):
7
+ return "es"
8
+ return "en"
9
+
10
+ def save_history(history, filename="chat_history.json"):
11
+ with open(filename, "w", encoding="utf-8") as f:
12
+ json.dump(history, f, ensure_ascii=False, indent=2)
13
+
14
+ def load_history(filename="chat_history.json"):
15
+ if os.path.exists(filename):
16
+ with open(filename, "r", encoding="utf-8") as f:
17
+ return json.load(f)
18
+ return []