Download code/learning.py from kartik20032003/sunai: direct link, hf CLI and curl.
- Browser
- Download file 716 Bytes
-
https://huggingface.co/kartik20032003/sunai/resolve/main/code/learning.py
- Command line
-
hf download hf://kartik20032003/sunai/code/learning.py
-
curl -L -o learning.py https://huggingface.co/kartik20032003/sunai/resolve/main/code/learning.py
716 Bytes
| import subprocess | |
| import sys | |
| from database import save_conversation as _db_save, get_conversation_count | |
| RETRAIN_EVERY = 5 # auto-retrain SunAI every N conversations | |
| def save_conversation(user_input, bot_reply, intent="casual", tone="casual"): | |
| _db_save(user_input, bot_reply, intent, tone) | |
| _maybe_retrain() | |
| def _maybe_retrain(): | |
| count = get_conversation_count() | |
| if count % RETRAIN_EVERY == 0: | |
| print(f"\n[SunAI] {count} conversations reached — retraining in background...\n") | |
| subprocess.Popen( | |
| [sys.executable, "sunai.py"], | |
| stdout=subprocess.DEVNULL, | |
| stderr=subprocess.DEVNULL, | |
| creationflags=subprocess.CREATE_NO_WINDOW | |
| ) | |