Docs

Documentation

How the playground talks to the model, and how to point it at your own fine-tuned checkpoint.

Enabling live predictions

The API route falls back to a small offline demo whenever no token is configured, so the site works out of the box. To call a real model, set an environment variable in your Vercel project (Settings → Environment Variables):

HUGGINGFACE_API_TOKEN=hf_xxxxxxxxxxxxxxxxxxxx

# optional — defaults to the base pretrained model
HF_MODEL_ID=surajp/gpt2-hindi

Get a free token from your Hugging Face account settings under “Access Tokens”. To serve your own fine-tuned checkpoint instead of the base model, push it to the Hub with model.push_to_hub(...) and point HF_MODEL_ID at that repo.

POST /api/predict

Request body:

{
  "prompt": "भारत एक",
  "mode": "next-word",   // or "complete"
  "k": 5                  // next-word candidates to return (1–8)
}

Response — next-word mode:

{
  "mode": "next-word",
  "prompt": "भारत एक",
  "candidates": [
    { "word": "देश", "score": 0.42 },
    { "word": "बड़ा", "score": 0.18 }
  ],
  "source": "model"   // or "offline"
}

Response — complete mode:

{
  "mode": "complete",
  "prompt": "भारत एक",
  "completion": "भारत एक विशाल और विविधताओं से भरा देश है।",
  "source": "model"
}

Why next-word scores are sampled, not exact

The notebook’s predict_next_word reads exact softmax probabilities off the model’s raw logits — possible when you hold the weights locally, but not exposed by the hosted Inference API used here. Instead the route draws several short samples from the model, tallies the first whole word from each, and reports the tally as an approximate score. Running your own model server would let you restore exact logit-based scoring.

Local development

npm install
npm run dev
# open http://localhost:3000