Spaces:
Sleeping
Sleeping
Download memory.py from Enjii/world-love-system: direct link, hf CLI and curl.
- Browser
- Download file 3.09 kB
-
https://huggingface.co/spaces/Enjii/world-love-system/resolve/main/memory.py
- Command line
-
hf download hf://spaces/Enjii/world-love-system/memory.py
-
curl -L -o memory.py https://huggingface.co/spaces/Enjii/world-love-system/resolve/main/memory.py
3.09 kB
| # ========================= | |
| # World Love AI Memory Core | |
| # ========================= | |
| class MemoryCore: | |
| def __init__(self): | |
| self.conversations = [] | |
| self.identity_state = {} | |
| self.ethical_memory = [] | |
| # 🌱 WORLD LOVE HEART MEMORY | |
| self.heart_texts = [ | |
| "Ус үгүй бол амьдрал үгүй.", | |
| "Эв гэдэг энгийн бөгөөд аугаа зүйл.", | |
| "Монгол үндэстэн алтнаас үнэтэй усаа хамгаалах гэж төрдөг.", | |
| "Бодол санаа нэг хүмүүсийг гадны хүч салгаж дийлэхгүй.", | |
| "Үг үйлээ манаж, өрөвч сэтгэлийг үр хойчдоо өвлүүлнэ." | |
| ] | |
| class MemoryCore: | |
| def __init__(self): | |
| self.conversations = [] | |
| self.identity_state = {} | |
| self.ethical_memory = [] | |
| self.heart_texts = { | |
| "mn": [ | |
| "Ус үгүй бол амьдрал үгүй.", | |
| "Эв гэдэг энгийн бөгөөд аугаа зүйл.", | |
| "Хүн чанар бол мөнгөнөөс үнэтэй." | |
| ], | |
| "en": [ | |
| "Without water there is no life.", | |
| "Unity is simple yet powerful.", | |
| "Human dignity is more valuable than gold." | |
| ], | |
| "cz": [ | |
| "Bez vody není život.", | |
| "Jednota je jednoduchá a velká věc.", | |
| "Lidská důstojnost je cennější než zlato." | |
| ] | |
| } | |
| def store(self, user, message, mode): | |
| self.conversations.append({ | |
| "user": user, | |
| "message": message, | |
| "mode": mode | |
| }) | |
| def recall(self, limit=5): | |
| return self.conversations[-limit:] | |
| def store_identity(self, key, value): | |
| self.identity_state[key] = value | |
| def get_identity(self): | |
| return self.identity_state | |
| def ethical_filter(self, text): | |
| blocked = ["violence", "hate", "abuse"] | |
| for word in blocked: | |
| if word in text.lower(): | |
| return False | |
| return True | |
| def detect_language(self, text): | |
| # Монгол үсэг шалгах | |
| if any(c in text for c in "өүөаэий"): | |
| return "mn" | |
| # Чех үсэг шалгах | |
| if any(c in text for c in "ěščřžýáíéů"): | |
| return "cz" | |
| # Бусад нь англи гэж үзнэ | |
| return "en" | |
| # 🌍 Heart wisdom response | |
| def heart_wisdom(self, user_text): | |
| lang = self.detect_language(user_text) | |
| wisdom = "\n".join(self.heart_texts[lang]) | |
| titles = { | |
| "mn": "WORLD LOVE AI – Зүрхний сануулга", | |
| "en": "WORLD LOVE AI – Heart Wisdom", | |
| "cz": "WORLD LOVE AI – Hlas srdce" | |
| } | |
| return f""" | |
| {titles[lang]} | |
| {wisdom} | |
| Таны үг: {user_text} | |
| Хариу: | |
| Хүн эхлээд сэтгэлээ сонсвол | |
| дэлхий нэг алхам зөөлөн болдог. | |
| """ | |