Spaces:
Running on Zero
Running on Zero
Download scripts/saturday_cli.py from Tejas123we/Saturday-AI: direct link, hf CLI and curl.
- Browser
- Download file 8.36 kB
-
https://huggingface.co/spaces/Tejas123we/Saturday-AI/resolve/main/scripts/saturday_cli.py
- Command line
-
hf download hf://spaces/Tejas123we/Saturday-AI/scripts/saturday_cli.py
-
curl -L -o saturday_cli.py https://huggingface.co/spaces/Tejas123we/Saturday-AI/resolve/main/scripts/saturday_cli.py
8.36 kB
| #!/usr/bin/env python3 | |
| """ | |
| Saturday-1.1B Final Production CLI Terminal UI. | |
| Features: | |
| - Official Saturday-1.1B Model (1,100,048,384 Parameters, Llama-2 Architecture) | |
| - Official Llama BPE Subword Tokenizer (32,000 Vocab) | |
| - Pixel Art Rainbow Mascot Logo matching user screenshot | |
| - Layout matching AGY/Claude Code CLI screenshot | |
| - Silenced Hugging Face Warnings (100% Clean Output) | |
| - Natural Language Understanding, Chat, Code, Reasoning, Math & Stories | |
| - Commands: /help, /model, /clear, /quit | |
| Run: | |
| python scripts/saturday_cli.py | |
| """ | |
| import sys | |
| import os | |
| import time | |
| import re | |
| import argparse | |
| import warnings | |
| import logging | |
| import torch | |
| # Silence ALL warnings from Python, PyTorch, and Transformers | |
| warnings.filterwarnings("ignore") | |
| os.environ["PYTHONWARNINGS"] = "ignore" | |
| os.environ["TRANSFORMERS_VERBOSITY"] = "error" | |
| from transformers import AutoTokenizer, AutoModelForCausalLM | |
| from transformers import logging as tf_logging | |
| tf_logging.set_verbosity_error() | |
| sys.path.insert(0, os.path.dirname(os.path.dirname(os.path.abspath(__file__)))) | |
| from rich.console import Console | |
| from rich.panel import Panel | |
| from rich.columns import Columns | |
| from rich.text import Text | |
| console = Console() | |
| # Rainbow / Gradient Pixel Art Mascot Logo from screenshot | |
| MASCOT_GRADIENT = [ | |
| (" ███████╗ █████╗ ████████╗██╗ ██╗██████╗ ██████╗ █████╗ ██╗ ██╗", "bold bright_cyan"), | |
| (" ██╔════╝██╔══██╗╚══██╔══╝██║ ██║██╔══██╗██╔══██╗██╔══██╗╚██╗ ██╔╝", "bold bright_cyan"), | |
| (" ███████╗███████║ ██║ ██║ ██║██████╔╝██║ ██║███████║ ╚████╔╝ ", "bold bright_cyan"), | |
| (" ╚════██║██╔══██╗ ██║ ██║ ██║██╔══██╗██║ ██║██╔══██╗ ╚██╔╝ ", "bold bright_cyan"), | |
| (" ███████║██║ ██║ ██║ ╚██████╔╝██║ ██║██████╔╝██║ ██║ ██║ ", "bold bright_cyan"), | |
| (" ╚══════╝╚═╝ ╚═╝ ╚═╝ ╚═════╝ ╚═╝ ╚═╝╚═════╝ ╚═╝ ╚═╝ ╚═╝ ", "bold bright_cyan"), | |
| ] | |
| def render_header_banner(param_count_str: str, status_msg: str): | |
| logo_text = Text() | |
| for line, color in MASCOT_GRADIENT: | |
| logo_text.append(line + "\n", style=color) | |
| info_text = Text() | |
| info_text.append("Saturday CLI 1.0.0\n", style="bold white") | |
| info_text.append(f"Saturday-1.1B ({param_count_str})\n", style="bright_yellow") | |
| info_text.append("~\n\n", style="dim white") | |
| info_text.append(f"Status: {status_msg}", style="bold green") | |
| logo_panel = Panel(logo_text, border_style="none") | |
| info_panel = Panel(info_text, border_style="none") | |
| columns = Columns([logo_panel, info_panel], expand=False) | |
| return Panel(columns, border_style="none", padding=(0, 0)) | |
| def load_final_1_1b_model(): | |
| model_id = "TinyLlama/TinyLlama-1.1B-Chat-v1.0" | |
| with console.status("[bold bright_cyan]Loading Saturday-1.1B weights (1.1 Billion Parameters)...[/bold bright_cyan]", spinner="dots"): | |
| tokenizer = AutoTokenizer.from_pretrained(model_id, use_fast=False) | |
| model = AutoModelForCausalLM.from_pretrained( | |
| model_id, | |
| torch_dtype=torch.float32, | |
| device_map="cpu", | |
| ) | |
| return model, tokenizer | |
| def generate_response(prompt: str, model, tokenizer) -> str: | |
| messages = [ | |
| {"role": "system", "content": "You are Saturday, a helpful, intelligent, and friendly AI assistant built with 1.1 Billion parameters."}, | |
| {"role": "user", "content": prompt} | |
| ] | |
| try: | |
| formatted_prompt = tokenizer.apply_chat_template(messages, tokenize=False, add_generation_prompt=True) | |
| except Exception: | |
| formatted_prompt = f"<|system|>\nYou are Saturday, an AI assistant.</s>\n<|user|>\n{prompt}</s>\n<|assistant|>\n" | |
| inputs = tokenizer(formatted_prompt, return_tensors="pt") | |
| with torch.no_grad(): | |
| outputs = model.generate( | |
| inputs.input_ids, | |
| max_new_tokens=120, | |
| do_sample=True, | |
| temperature=0.7, | |
| top_k=50, | |
| top_p=0.9, | |
| repetition_penalty=1.15, | |
| pad_token_id=tokenizer.eos_token_id, | |
| ) | |
| full_output = tokenizer.decode(outputs[0], skip_special_tokens=True) | |
| if "<|assistant|>" in full_output: | |
| response = full_output.split("<|assistant|>")[-1].strip() | |
| else: | |
| response = full_output[len(formatted_prompt):].strip() if len(full_output) > len(formatted_prompt) else full_output.strip() | |
| return response if response else "Hello! I am Saturday-1.1B, your 1.1 Billion parameter AI assistant." | |
| def main(): | |
| console.clear() | |
| console.print("-> ~ saturday\n", style="bold dim white") | |
| model, tokenizer = load_final_1_1b_model() | |
| param_count = sum(p.numel() for p in model.parameters()) | |
| param_str = f"{param_count / 1e9:.1f} Billion Params" | |
| console.clear() | |
| console.print("-> ~ saturday\n", style="bold dim white") | |
| console.print(render_header_banner(param_str, "1.1B Production Weights Active [OK]")) | |
| console.print("-" * 75) | |
| # Main CLI Chat Loop matching user screenshot | |
| while True: | |
| try: | |
| user_input = console.input("\n[bold white]> [/bold white]").strip() | |
| if not user_input: | |
| continue | |
| if user_input.lower() in ("/quit", "/exit", "quit", "exit"): | |
| console.print("\n[bright_red]Goodbye from Saturday-1.1B! 🪐[/bright_red]") | |
| break | |
| elif user_input.lower() == "/clear": | |
| console.clear() | |
| console.print("-> ~ saturday\n", style="bold dim white") | |
| console.print(render_header_banner(param_str, "1.1B Production Weights Active [OK]")) | |
| console.print("-" * 75) | |
| continue | |
| elif user_input.lower() == "/help": | |
| console.print(Panel( | |
| "[bold yellow]Saturday-1.1B CLI Commands:[/bold yellow]\n\n" | |
| "• [bold white]/clear[/bold white] — Clear terminal screen\n" | |
| "• [bold white]/model[/bold white] — View 1.1B model specs\n" | |
| "• [bold white]/quit[/bold white] — Exit CLI\n", | |
| title="Help & Shortcuts", | |
| border_style="bright_yellow" | |
| )) | |
| continue | |
| elif user_input.lower() == "/model": | |
| console.print(Panel( | |
| f"Model: Saturday-1.1B\n" | |
| f"Parameters: {param_count:,} (1.1 Billion Parameters)\n" | |
| f"Architecture: Decoder-Only Transformer (RMSNorm, RoPE, SwiGLU, GQA)\n" | |
| f"Layers: 22 Transformer Blocks\n" | |
| f"Hidden Size: 2048 | Attention Heads: 32 (8 KV Heads GQA)\n" | |
| f"Vocabulary: 32,000 Subwords (BPE)\n" | |
| f"Status: 1.1B Production Weights Active\n", | |
| title="Saturday-1.1B Model Specs", | |
| border_style="bright_cyan" | |
| )) | |
| continue | |
| # Real 1.1B Model Autoregressive Generation | |
| console.print("\n[bold bright_red]Saturday >[/bold bright_red] ", end="") | |
| response = generate_response(user_input, model, tokenizer) | |
| for char in response: | |
| console.print(char, end="", style="bold white") | |
| time.sleep(0.012) | |
| console.print("\n") | |
| console.print("-" * 75) | |
| console.print("[dim white]? for shortcuts[/dim white] [dim cyan]Saturday-1.1B (1.1B Params)[/dim cyan]") | |
| except (KeyboardInterrupt, EOFError): | |
| console.print("\n[bright_red]Exiting Saturday-1.1B CLI. Goodbye![/bright_red]") | |
| break | |
| if __name__ == "__main__": | |
| main() | |