Text Generation
LiteRT
LiteRT
Russian
English
1m-parameters
reverse
tabular
regression
mini
mobile
optimized
speed
flash
numpy
eco
slm
lm
mini-llm
llm
generation
text
small
useless
tensorflow
Instructions to use KrynexLabs/KrynexAI-vNS-Reverse-Mobile-TFLite with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- LiteRT
How to use KrynexLabs/KrynexAI-vNS-Reverse-Mobile-TFLite with LiteRT:
# No code snippets available yet for this library. # To use this model, check the repository files and the library's documentation. # Want to help? PRs adding snippets are welcome at: # https://github.com/huggingface/huggingface.js
- Notebooks
- Google Colab
- Kaggle
Download python scripts/script.py from KrynexLabs/KrynexAI-vNS-Reverse-Mobile-TFLite: direct link, hf CLI and curl.
- Browser
- Download file 3.42 kB
-
https://huggingface.co/KrynexLabs/KrynexAI-vNS-Reverse-Mobile-TFLite/resolve/main/python%20scripts/script.py
- Command line
-
hf download 'hf://KrynexLabs/KrynexAI-vNS-Reverse-Mobile-TFLite/python scripts/script.py'
-
curl -L -o script.py https://huggingface.co/KrynexLabs/KrynexAI-vNS-Reverse-Mobile-TFLite/resolve/main/python%20scripts/script.py
3.42 kB
| import numpy as np | |
| import json | |
| import os | |
| import struct | |
| from pathlib import Path | |
| class ReverseAI: | |
| def __init__(self, save_dir="ReverseModel"): | |
| self.save_dir = Path(save_dir) | |
| self.save_dir.mkdir(exist_ok=True) | |
| self.char_to_idx = {} | |
| self.idx_to_char = {} | |
| self.next_idx = 0 | |
| self._add_chars("abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ") | |
| self._add_chars("0123456789") | |
| self._add_chars(" .,!?-:;()[]{}'\"") | |
| self.load_model() | |
| def _add_chars(self, chars): | |
| for c in chars: | |
| if c not in self.char_to_idx: | |
| self.char_to_idx[c] = self.next_idx | |
| self.idx_to_char[self.next_idx] = c | |
| self.next_idx += 1 | |
| def _ensure_char(self, c): | |
| if c not in self.char_to_idx: | |
| self.char_to_idx[c] = self.next_idx | |
| self.idx_to_char[self.next_idx] = c | |
| self.next_idx += 1 | |
| def encode(self, text): | |
| for c in text: | |
| self._ensure_char(c) | |
| return np.array([self.char_to_idx[c] for c in text], dtype=np.int32) | |
| def decode(self, indices): | |
| return ''.join(self.idx_to_char[int(i)] for i in indices) | |
| def reverse(self, text): | |
| if not text: | |
| return "" | |
| indices = self.encode(text) | |
| reversed_indices = indices[::-1] | |
| result = self.decode(reversed_indices) | |
| self.save_model() | |
| return result | |
| def save_model(self): | |
| vocab_file = self.save_dir / "vocab.json" | |
| with open(vocab_file, 'w', encoding='utf-8') as f: | |
| json.dump({ | |
| 'char_to_idx': self.char_to_idx, | |
| 'idx_to_char': {str(k): v for k, v in self.idx_to_char.items()}, | |
| 'vocab_size': self.next_idx | |
| }, f, ensure_ascii=False, indent=2) | |
| model_file = self.save_dir / "model.bin" | |
| with open(model_file, 'wb') as f: | |
| f.write(b'RVAI') | |
| f.write(struct.pack('I', 1)) | |
| f.write(struct.pack('I', self.next_idx)) | |
| for idx in range(self.next_idx): | |
| char = self.idx_to_char[idx] | |
| encoded = char.encode('utf-8') | |
| f.write(struct.pack('I', len(encoded))) | |
| f.write(encoded) | |
| def load_model(self): | |
| vocab_file = self.save_dir / "vocab.json" | |
| if vocab_file.exists(): | |
| try: | |
| with open(vocab_file, 'r', encoding='utf-8') as f: | |
| data = json.load(f) | |
| self.char_to_idx = data['char_to_idx'] | |
| self.idx_to_char = {int(k): v for k, v in data['idx_to_char'].items()} | |
| self.next_idx = data['vocab_size'] | |
| return True | |
| except: | |
| return False | |
| return False | |
| def main(): | |
| ai = ReverseAI() | |
| print("="*50) | |
| print("KrynexAI Reverse Model") | |
| print("Type 'exit' to quit") | |
| print("="*50) | |
| while True: | |
| word = input("\n🗣 Enter word: ").strip() | |
| if word.lower() in ['exit', 'quit']: | |
| print("👋 Goodbye!") | |
| break | |
| if not word: | |
| print("⚠️ Please enter something!") | |
| continue | |
| result = ai.reverse(word) | |
| print(f"🔄 Reversed: {result}") | |
| if __name__ == "__main__": | |
| main() |