Really-Amazing commited on
Commit
6534cf7
·
verified ·
1 Parent(s): cff6f6c

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +15 -15
app.py CHANGED
@@ -1,35 +1,35 @@
1
  import gradio as gr
2
  import torch
3
  from nanochat.engine import Engine
 
 
4
 
5
  MODEL_PATH = "model_000971.pt"
6
  META_PATH = "meta_000971.json"
7
 
8
  print("Waking up the toddler (NanoChat-ClimbMix-D12)...")
9
- engine = Engine(model_path=MODEL_PATH, meta_path=META_PATH, device="cpu")
10
 
11
- def chat_fn(message):
12
- response = engine.generate(message, max_new_tokens=300, temperature=0.85) # higher temp = more fun/confident nonsense
 
 
 
 
 
 
 
 
 
13
  return response
14
 
15
  with gr.Blocks(theme=gr.themes.Soft(primary_hue="blue")) as demo:
16
  gr.Markdown("# 🧸 NanoChat-ClimbMix-D12 – The Confident Toddler LLM")
17
- gr.Markdown("Inspired by Andrej Karpathy's nanochat. Currently in 'Preschool Phase': 100% confident spelling, 0% reliable facts. 😂")
18
- gr.Markdown("**Coming soon:** D14 (Elementary), D16 (Middle School), D18 (High School), D20+ (University level) – less hallucinations, more wisdom!")
19
-
20
- with gr.Accordion("⚠️ Hallucination Disclaimer", open=True):
21
- gr.Markdown("This model boldly answers everything — even when wrong. Enjoy the comedy! Next versions will grow up fast.")
22
 
23
  gr.ChatInterface(
24
  fn=chat_fn,
25
- examples=[
26
- "Why is the sky blue?",
27
- "How many planets are in the solar system?",
28
- "Write Python code to say hello world",
29
- "Explain photosynthesis in one sentence"
30
- ],
31
  title="Chat with the Toddler",
32
- description="Ask anything it will reply with maximum confidence!"
33
  )
34
 
35
  if __name__ == "__main__":
 
1
  import gradio as gr
2
  import torch
3
  from nanochat.engine import Engine
4
+ from nanochat.checkpoint_manager import load_model
5
+ from nanochat.tokenizer import get_tokenizer
6
 
7
  MODEL_PATH = "model_000971.pt"
8
  META_PATH = "meta_000971.json"
9
 
10
  print("Waking up the toddler (NanoChat-ClimbMix-D12)...")
 
11
 
12
+ # 1. Load the tokenizer and model first
13
+ tokenizer = get_tokenizer(META_PATH)
14
+ model, _ = load_model(MODEL_PATH, device="cpu")
15
+
16
+ # 2. Pass the objects to the Engine
17
+ engine = Engine(model=model, tokenizer=tokenizer)
18
+
19
+ def chat_fn(message, history):
20
+ # Based on your engine.py, it expects a list of tokens or a string?
21
+ # Usually, generate handles the string-to-token conversion.
22
+ response = engine.generate(message, max_tokens=300, temperature=0.85)
23
  return response
24
 
25
  with gr.Blocks(theme=gr.themes.Soft(primary_hue="blue")) as demo:
26
  gr.Markdown("# 🧸 NanoChat-ClimbMix-D12 – The Confident Toddler LLM")
27
+ gr.Markdown("Inspired by Andrej Karpathy's nanochat. Currently in 'Preschool Phase'!")
 
 
 
 
28
 
29
  gr.ChatInterface(
30
  fn=chat_fn,
 
 
 
 
 
 
31
  title="Chat with the Toddler",
32
+ examples=["Why is the sky blue?", "Tell me a joke."],
33
  )
34
 
35
  if __name__ == "__main__":